iOS 控件切圆角
2018-03-16 本文已影响0人
麓庵
控件如果切四个圆角的话,调用下面的代码
self.layer.cornerRadius = 2.0f ;
self.layer.masksToBounds = true ; //
如果只是切某几个角的话,调用以下的代码
UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)] ;
CAShapeLayer * sublayer = [[CAShapeLayer alloc] init] ;
sublayer.frame = rect ;
sublayer.path = path.CGPath ;
self.layer.mask = sublayer ;
UIRectCorner的值
typedef NS_OPTIONS(NSUInteger, UIRectCorner) {
UIRectCornerTopLeft = 1 << 0,
UIRectCornerTopRight = 1 << 1,
UIRectCornerBottomLeft = 1 << 2,
UIRectCornerBottomRight = 1 << 3,
UIRectCornerAllCorners = ~0UL
};