答案 0 :(得分: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];
答案 1 :(得分: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
答案 2 :(得分:0)
UIViews(其中UITextView是一个子类)有一个名为backgroundColor的属性。
@property(nonatomic, copy) UIColor *backgroundColor
尝试在TextView上调用[textView setBackgroundColor:[UIColor clearColor]]并在其后面放置一个图像视图。