我有一个类别中的以下代码进行四舍五入.我也想画边界.但边角没有显示在角落的圆角上.
这是代码
- (void) roundTopCorners:(CGFloat) radius { self.layer.masksToBounds = YES; CGRect bounds = self.bounds; UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii:CGSizeMake(radius,radius)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = bounds; maskLayer.path = maskPath.CGPath; maskLayer.strokeColor = [UIColor redColor].CGColor; self.layer.mask = maskLayer; }
解决方法
掩模层不被绘制,仅用于计算掩模.尝试:
-(void)roundCorners:(UIRectCorner)corners radius:(CGFloat)radius { CGRect bounds = self.bounds; UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:corners cornerRadii:CGSizeMake(radius,radius)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = bounds; maskLayer.path = maskPath.CGPath; self.layer.mask = maskLayer; CAShapeLayer* frameLayer = [CAShapeLayer layer]; frameLayer.frame = bounds; frameLayer.path = maskPath.CGPath; frameLayer.strokeColor = [UIColor redColor].CGColor; frameLayer.fillColor = nil; [self.layer addSublayer:frameLayer]; } -(void)roundTopCornersRadius:(CGFloat)radius { [self roundCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) radius:radius]; } -(void)roundBottomCornersRadius:(CGFloat)radius { [self roundCorners:(UIRectCornerBottomLeft|UIRectCornerBottomRight) radius:radius]; }
您当前看到的框架是UITextField的正常框架,因此将框架样式设置为none.您还必须调整插图来弥补将框架样式设置为无,通常没有插入的事实.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。