我正在准备在 iOS 5 GM 上发布我的 iPhone 应用程序,并遇到了 UIView 的错误。当我在子类上重写 drawRect 方法时,模拟器会显示所需的结果,但当我尝试在实际设备上测试时,drawRect 重写根本没有任何效果。
我什至将一条日志语句放置在一个drawRect覆盖中并确认它正在被调用。
还有其他人注意到这个问题吗?
这是我正在使用的覆盖代码:
- (void)drawRect:(CGRect)rect {
DebugLog( @"*** calling drawRect ***" );
CGContextRef context = UIGraphicsGetCurrentContext();
// draw the dark gray background
CGContextSetFillColor(context, [SkinManager getWhiteColor]);
CGContextFillRect(context, CGRectMake(0.0, 0.0, rect.size.width, rect.size.height));
// draw the text field background in white
CGContextSetFillColor(context, [SkinManager getDarkGray]);
CGContextFillRect(context, CGRectMake(2.0, 2.0, rect.size.width - 4, rect.size.height - 4));
}
这是生成颜色的代码
+(const CGFloat*) getDarkGray {
UIColor *color = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
return [self getCGColor:color];
}
+(const CGFloat*) getCGColor: (UIColor*)color {
CGColorRef colorref = [color CGColor];
const CGFloat *components = CGColorGetComponents(colorref);
return components;
}
同样,此代码在 iOS 4.x 和 iOS 5 模拟器中完美运行。唯一损坏的地方是 iOS 5 设备。