設(shè)置固定圓角,iOS11之后有更簡單的方法(適配如下)
特別注意啸如,在iOS10版本下,UITableview通過Masonry約束后直接用下面的方法設(shè)置圓角,結(jié)果UITableview不顯示蒜撮,可以直接frame賦值
/**
圓角
@param radius 圓角尺寸
@param maskCorner 圓角位置列如:kCALayerMinXMinYCorner|kCALayerMaxXMinYCorner
@param corner 圓角位置列如:UIRectCornerTopRight|UIRectCornerTopLeft
*/
- (void)acs_radiusWithRadius:(CGFloat)radius maskedCorner:(CACornerMask)maskCorner corner:(UIRectCorner)corner {
if (@available(iOS 11.0, *)) {
self.layer.cornerRadius = radius;
self.layer.maskedCorners = maskCorner;
} else {
UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = path.CGPath;
self.layer.mask = maskLayer;
}
}
UIRectCorner的定義如下:
typedef NS_OPTIONS(NSUInteger, UIRectCorner) {
UIRectCornerTopLeft = 1 << 0,
UIRectCornerTopRight = 1 << 1,
UIRectCornerBottomLeft = 1 << 2,
UIRectCornerBottomRight = 1 << 3,
UIRectCornerAllCorners = ~0UL
};
CACornerMask的定義如下:
typedef NS_OPTIONS (NSUInteger, CACornerMask)
{
kCALayerMinXMinYCorner = 1U << 0, // 左上
kCALayerMaxXMinYCorner = 1U << 1, 右上
kCALayerMinXMaxYCorner = 1U << 2, // 左下
kCALayerMaxXMaxYCorner = 1U << 3, // 右下
};
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者