2009-04-18 5 views
1

내 애플 리케이션에서 UITextView 배경을 추가 할 오전. 그러나 텍스트보기가 아래로 스크롤 될 때 이미지는 텍스트와 함께 가고 새 텍스트 줄 배경은 흰색으로 보입니다. 거기에 대처하는 쉬운 방법이 있습니까? 나는 배경 텍스트를 그 위에 스크롤와 정적으로 유지하려는배경 스크롤

textView = [ [UITextView alloc] initWithFrame: CGRectMake(10, 100, 270, 130)]; 

UIImageView *imgView = [ [UIImageView alloc]initWithFrame: CGRectMake(0, 0, 270, 130)]; 
imgView.image = [UIImage imageNamed: @"background.png"]; 
[textView addSubview: imgView]; 
[textView sendSubviewToBack: imgView]; 
[imgView release]; 


textView.opaque = YES; 
textView.editable = YES; 
textView.font = [UIFont systemFontOfSize: 12]; 
textView.textColor = [UIColor colorWithRed: 10.0f/255.0f green: 10.0f/255.0f blue: 10.0f/255.0f alpha: 1.0f]; 
textView.autocapitalizationType = UITextAutocapitalizationTypeNone; 
textView.delegate = self; 

[mainScrollView addSubview: textView]; 

: 다음은 내 코드입니다.

+0

당신이 배경이 스크롤로 이동하거나 그 위에 스크롤 텍스트 정적으로 유지 하시겠습니까? – pgb

+0

배경 위에 텍스트를 스크롤하면서 배경을 고정시키고 싶습니다. –

답변

2

배경을 정적으로 유지하고 텍스트 스크롤을 유지하려면 UISmrollView를 UIScrollView를 추가 할 동일한 뷰 (동일한 크기 등)에 추가하면됩니다. 뭔가 같은 :

UIImageView *imgView = [ [UIImageView alloc]initWithFrame: CGRectMake(0, 0, 270, 130)]; 
imgView.image = [UIImage imageNamed: @"background.png"]; 
[self addSubView:imgView]; 
[imgView release]; 

textView = [ [UITextView alloc] initWithFrame: CGRectMake(10, 100, 270, 130)]; 

textView.opaque = YES; 
textView.editable = YES; 
textView.font = [UIFont systemFontOfSize: 12]; 
textView.textColor = [UIColor colorWithRed: 10.0f/255.0f green: 10.0f/255.0f blue: 10.0f/255.0f alpha: 1.0f]; 
textView.autocapitalizationType = UITextAutocapitalizationTypeNone; 
textView.delegate = self; 
// Make the background of the textView transparent 
textView.backgroundColor = [UIColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 0.0]; 

[mainScrollView addSubview: textView]; 

이 코드가있는 UIView에서 실행되는 있으리라 믿고있어, 그래서있는 UIImageView 자체를 모두 추가 해요. UIViewController에서이 작업을 수행하는 경우 [self.view addSubView:mainScrollView]으로 변경할 수 있습니다.

0

감사합니다. pgb.

이 코드는 결국 나를 위해 작동 :

UIImageView *imgView = [ [UIImageView alloc]initWithFrame: CGRectMake(10, 100, 270, 130)]; 
    imgView.image = [UIImage imageNamed: @"background.png"]; 
    [mainScrollView addSubview: imgView]; 
    [mainScrollView sendSubviewToBack: imgView]; 
    [imgView release]; 

    textView = [ [UITextView alloc] initWithFrame: CGRectMake(10, 100, 270, 130)]; 

    textView.opaque = YES; 
    textView.editable = YES; 
    textView.font = [UIFont systemFontOfSize: 12]; 
    textView.textColor = [UIColor colorWithRed: 10.0f/255.0f green: 10.0f/255.0f blue: 10.0f/255.0f alpha: 1.0f]; 
    textView.autocapitalizationType = UITextAutocapitalizationTypeNone; 
    textView.delegate = self; 
    // Make the background of the textView transparent 
    textView.backgroundColor = [UIColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 0.0]; 

    [mainScrollView addSubview: textView]; 
+0

textView.backgroundColor = [UIColor clearColor]; –