我试图把一个UITextView放在UIAlertView的自定义子类中,我使用我的背景图像创建。 UITextView仅用于显示大量的文本(所以滚动)。 这里是我的子类的代码UIAlertView里面的UIAlertView子类
- (id)initNarrationViewWithImage:(UIImage *)image text:(NSString *)text{
if (self = [super init]) {
self.backgroundImage = image;
UITextView * textView = [[UITextView alloc] initWithFrame:CGRectZero];
self.textualNarrationView = textView;
[textView release];
self.textualNarrationView.text = text;
self.textualNarrationView.backgroundColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0];
self.textualNarrationView.opaque = YES;
[self addSubview:textualNarrationView];
}
return self;
}
- (void)drawRect:(CGRect)rect {
NSLog(@"DRAU");
CGSize imageSize = self.backgroundImage.size;
[self.backgroundImage drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
}
- (void)layoutSubviews {
CGSize imageSize = self.backgroundImage.size;
self.textualNarrationView.bounds = CGRectMake(0, 0, imageSize.width - 20, imageSize.height - 20);
self.textualNarrationView.center = CGPointMake(320/2, 480/2);
}
- (void)show{
[super show];
NSLog(@"SCIO");
CGSize imageSize = self.backgroundImage.size;
self.bounds = CGRectMake(0, 0, imageSize.width, imageSize.height);
self.center = CGPointMake(320/2, 480/2);
}
这是我第一次继承一个UIView,我肯定失去了一些东西,因为背景出现正确的图像,该UITextView的也不过一秒钟的一小部分后,所有跳跃(似乎是一个协调问题)。
如果我没有弄错,UIAlert会自动添加一个UITextView,如果屏幕上显示的文字过多... – dododedodonl 2010-08-14 10:54:51
那么我应该在什么地方添加我的文本? – rano 2010-08-14 10:58:10
目前我用UILabel代替另一个方向。如果我找到它,我会发布一个解决方案 – rano 2010-08-17 06:27:39