我试图在我的UIView子类中画一个雪佛龙形状。雪佛龙出现,但线帽样式和线连接样式,我正在应用,没有反映在输出。
- (UIBezierPath *)chevron:(CGRect)frame
{
UIBezierPath* bezierPath = [[UIBezierPath alloc]init];
[bezierPath setLineJoinStyle:kCGLineJoinRound];
[bezierPath setLineCapStyle:kCGLineCapRound];
[bezierPath moveToPoint:CGPointMake(CGRectGetMinX(frame), CGRectGetMaxY(frame))];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMaxX(frame), CGRectGetMaxY(frame) * 0.5)];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame), CGRectGetMinY(frame))];
return bezierPath;
}
-(void)drawRect:(CGRect)rect{
[self.color setStroke];
UIBezierPath *chevronPath = [self chevron:rect];
[chevronPath setLineWidth:self.strokeWidth];
[chevronPath stroke];
}
根据苹果公司的文档,他们说“在配置了Bezier路径的几何和属性之后,使用笔画和填充方法在当前的图形上下文中绘制路径”,但在这里不起作用--我已经尝试过移动setLineJoinStyle
和setLineCapStyle
语句(例如,在添加LineToPoint之后,在drawRect中),似乎不管我叫它们多少次,它都不起作用。有什么问题吗?
发布于 2014-06-22 07:59:14
您的代码正在应用这些样式,您只是看不到它们,因为您的雪佛龙一直被绘制到您的视图的边缘,然后被剪裁。若要查看您的chevron的末端,请将对chevron方法的调用更改为
UIBezierPath *chevronPath = [self chevron:CGRectInset(rect, 10, 10)];
10点是否足够的嵌入将取决于你的线有多宽,所以你可能需要增加。
https://stackoverflow.com/questions/24352719
复制