我使用以下方法对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;
}
答案 0 :(得分:0)
nameOfTextField.layer.cornerRadius = 15.0
nameOfTextField.layer.borderWidth = 2.0 // Use border width if you need it
答案 1 :(得分:0)
这样做的一种可能方法是重绘边框。正如
-(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 = self.imageView.bounds;
borderShape.path = path.CGPath;
borderShape.strokeColor = [UIColor blackColor].CGColor;
borderShape.fillColor = nil;
borderShape.lineWidth = 3;
[view.layer addSublayer:borderShape];
}
希望这会有所帮助。 Referred from this SO Post