CoreGraphics在iOS 7.0模拟器上不工作
自从iOS 7 alpha以来,我一直在努力解决这个问题。起初我以为这是阿尔法上的一个错误,但它仍然在发生,所以我做错了什么 在整个应用程序中,我都在用CG绘制细胞背景之类的东西,但在iOS 7中它并没有显示出来 例如:CoreGraphics在iOS 7.0模拟器上不工作,ios,core-graphics,ios7,Ios,Core Graphics,Ios7,自从iOS 7 alpha以来,我一直在努力解决这个问题。起初我以为这是阿尔法上的一个错误,但它仍然在发生,所以我做错了什么 在整个应用程序中,我都在用CG绘制细胞背景之类的东西,但在iOS 7中它并没有显示出来 例如: @interface NewManagerCell : UITableViewCell @end @implementation NewManagerCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIden
@interface NewManagerCell : UITableViewCell
@end
@implementation NewManagerCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
//some initialization code here
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect bounds = self.bounds;
bounds.origin.y += 5; //inter-cell spacing
bounds.size.height -= 5;
CGFloat mx = CGRectGetMinX(bounds);
CGFloat Mx = CGRectGetMaxX(bounds);
CGFloat my = CGRectGetMinY(bounds);
CGFloat cy = CGRectGetMinY(bounds)+CGRectGetHeight(bounds)*.375;
CGFloat My = CGRectGetMaxY(bounds);
CGContextBeginPath(context);
CGContextMoveToPoint(context, mx, cy);
CGContextAddLineToPoint(context, mx+cy-my, my);
CGContextAddLineToPoint(context, Mx-cy+my, my);
CGContextAddLineToPoint(context, Mx, cy);
CGContextAddLineToPoint(context, Mx, My);
CGContextAddLineToPoint(context, mx, My);
CGContextAddLineToPoint(context, mx, cy);
CGContextSetFillColorWithColor(context, [[UIColor colorWithPatternImage:[UIImage imageNamed:@"cell-pattern"]] CGColor]);
CGContextFillPath(context);
mx += 4+CGRectGetWidth(bounds)/4-CGRectGetHeight(bounds)*.375/16;
Mx -= 4;
my += 4;
My -= 4;
cy += 2;
CGMutablePathRef path = CGPathCreateMutable();
CGContextBeginPath(context);
CGPathMoveToPoint(path, &CGAffineTransformIdentity, mx, my);
CGPathAddLineToPoint(path, &CGAffineTransformIdentity, Mx-(cy-my), my);
CGPathAddLineToPoint(path, &CGAffineTransformIdentity, Mx, cy);
CGPathAddLineToPoint(path, &CGAffineTransformIdentity, Mx, My);
CGPathAddLineToPoint(path, &CGAffineTransformIdentity, mx, My);
CGPathAddLineToPoint(path, &CGAffineTransformIdentity, mx, my);
CGContextAddPath(context, path);
CGContextSetRGBFillColor(context, 1, 1, 1, 1);
CGContextFillPath(context);
CGContextAddPath(context, path);
CGContextSetRGBStrokeColor(context, .69, .69, .69, 1);
CGContextStrokePath(context);
CGPathRelease(path);
}
@end
在iOS 7之前的任何版本中都可以使用,但现在已经停止使用了。有人知道发生了什么吗?尝试创建一个包含要绘制的代码的自定义
UIView
,然后您可以将该子视图添加到单元格的根视图中 我上周遇到了同样的问题,并提出了相同的解决方案:-)您可以使用类似的方法来避免子类化。这是一个聪明的想法!如果这回答了您的问题,请将此标记为答案。谢谢:)