我正在使用以下方法来圆化 uitextfield 的特定角。但是,它具有删除圆角处边框的效果。任何人都可以建议在不删除边界的情况下执行此操作的方法吗?提前感谢您的任何建议。
-(void)roundBottomCornersOfView: (UITextField*) view by: (NSInteger) radius {
CGRect rect = view.bounds;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect
byRoundingCorners:UIRectCornerTopLeft |UIRectCornerTopRight
cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *layers = [CAShapeLayer layer];
layers.frame = rect;
layers.path = path.CGPath;
view.layer.mask = layers;
}
最佳答案
一种可能的方法是重新绘制边框。作为
-(void)roundBottomCornersOfView: (UITextField*) view by: (NSInteger) radius {
CGRect rect = view.bounds;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect
byRoundingCorners:UIRectCornerTopLeft |UIRectCornerTopRight
cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *layers = [CAShapeLayer layer];
layers.frame = rect;
layers.path = path.CGPath;
view.layer.mask = layers;
CAShapeLayer* borderShape = [CAShapeLayer layer];
borderShape.frame = rect;
borderShape.path = path.CGPath;
borderShape.strokeColor = [UIColor blackColor].CGColor;
borderShape.fillColor = nil;
borderShape.lineWidth = 3;
[view.layer addSublayer:borderShape];
}
希望这对您有所帮助。 Referred from this SO Post
关于IOS/objective-C : Round top corners of rectangle without erasing border,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47186422/