我有这段代码可以在 a 中创建多个矩形UIView
:
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(ctx, 0.5);
CGContextSetStrokeColorWithColor(ctx, [UIColor blueColor].CGColor);
//newView.xPoints is always equal in count to the other two arrays below.
for (int i = 0; i < [newView.xPoints count]; i++)
{
CGFloat tx = [[newView.xPoints objectAtIndex:i]floatValue];
CGFloat ty = [[newView.yPoints objectAtIndex:i]floatValue];
CGFloat charWidth = [[newView.charArray objectAtIndex:i]floatValue];
CGRect rect = CGRectMake(tx, (theContentView.bounds.size.height - ty), charWidth, -10.5);
CGContextAddRect(ctx, rect);
CGContextStrokePath(ctx);
}
我试了一下,drawRect:
效果很好。但是,我计划drawRect:
用于其他目的。那么任何人都可以给我提示或提示如何在不使用的情况下做到这一点drawRect:
吗?