2011-02-22 132 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的,并把它后面的图像视图。