我做了一些研究,发现没有简单的方法 仅 UIView 圆的右上角和左上角,对吧?
附言。此代码使所有 4 个角变圆,这是 smth。我不想。
#import <QuartzCore/QuartzCore.h>
self.layer.cornerRadius = 5;
self.layer.masksToBounds = YES;
最佳答案
你可以用这个片段来做:
// Set top right & left corners
[self setMaskTo:yourView byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight];
编辑
对不起,我忘记了
- (void)setMaskTo:(UIView*)view byRoundingCorners:(UIRectCorner)corners
{
UIBezierPath *rounded = [UIBezierPath bezierPathWithRoundedRect:view.bounds
byRoundingCorners:corners
cornerRadii:CGSizeMake(8.0, 8.0)];
CAShapeLayer *shape = [[CAShapeLayer alloc] init];
[shape setPath:rounded.CGPath];
view.layer.mask = shape;
}
PS:正如我在评论中所说,如果您在显示 UITableViewCell
单元格时使用类似的东西,我发现使用背景图像总是更好的选择,因为这种绘图的东西总是影响性能。
关于iphone - 使 UIView 的特定角变圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14067897/