在我的应用程序中我试图在矩形中显示图像并使用DrawRect方法。问题出在输出端什么也看不到。模拟器中只有空白屏幕。这是代码:
- (void)viewDidLoad {
[super viewDidLoad];
[self drawRect:CGRectMake(78, 43, 222, 138)];
}
- (void)drawRect:(CGRect)rect {
UIImage *myImage = [UIImage imageNamed:@"btbp.jpg"];
CGRect imageRect = CGRectMake(10, 10, 300, 400);
[myImage drawInRect:imageRect];
//[self setNeedsDisplay];
[myImage release];
}
答案 0 :(得分:0)
调用drawRect没有任何效果。相反,你应该调用setNeedsDisplay来强制重绘。