答案 0 :(得分:1)
如果您创建UIView
的子类,例如CustomView
,您唯一需要做的就是实施drawRect:
方法:
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
// set fill & stroke color
[[UIColor blueColor] setStroke];
[[UIColor purpleColor] setFill];
// create blocks
CGFloat blockWidth = self.bounds.size.width / 3;
CGFloat blockHeight = self.bounds.size.height;
for (int i = 0; i < 3; i++) {
UIBezierPath *path = [UIBezierPath bezierPathWithRect:
CGRectMake(blockWidth * i, 0, blockWidth, blockHeight);
path.lineWidth = 2;
[path fill];
[path stroke];
}
}