2009-04-18 13 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

あなたは、背景が静止したまま、それの上にテキストスクロールを持って、ちょうどあなたが(同じ寸法、などで)にUIScrollViewのを追加している同じビューにUIImageViewを追加したい場合。 何かのように:

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]; –

関連する問題