2011-02-22 108 views

回答

5

在viewDidLoad中

textView.backgroundColor = [UIColor clearColor]; 
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:textView.frame] autorelease]; 
imageView.image = [UIImage imageNamed:@"myBackgroundImage.png"]; 
[self.view addSubview:imageView]; 
[self.view bringSubviewToFront:textView]; 
2

試着做一個新班。 (沒有測試代碼,只需鍵入它在論壇上,嘗試以其他方式使用代碼:使用的概念)

@interface TextViewWithImage : UIView { 
    UITextView *textView; 
    UIImageView *imageView; 
} 

@property (retain, readonly) UITextView *textView; 
@property (retain, readonly) UIImageView *imageView; 

@implementation TextViewWithImage 

- (id) init { 
    if (self = [super init]) { 
     [self setupContentViews]; 
    } 
    return self; 
} 

- (id) initWithFrame:(CGRect)frame { 
    if (self = [super initWithFrame:frame]) { 
     [self setupContentViews]; 
    } 
    return self; 
} 

- (void) setupContentViews { 
    textView = [[UITextView alloc] init]; 
    imageView = [[UIImageView alloc] init]; 

    textView.frame = self.frame; 
    imageView.frame = self.frame; 

    textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
    imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
} 

- (void) dealloc { 
    [textView release]; 
    [imageView release]; 
    [super dealloc]; 
} 
@end 
0

UIViews(其中的UITextView是一個子類)有一個名爲backgroundColor的屬性。

@property(nonatomic, copy) UIColor *backgroundColor 

嘗試調用[TextView的setBackgroundColor:的UIColor clearColor]]關於TextView的,並把它後面的圖像視圖。