我有一个 UITextView,我在其图层上设置了边框宽度、边框颜色和圆角半径属性,外部看起来很棒。不过border的内侧没有像外侧那样有圆角,看起来有点滑稽。有没有办法使边框的内角变圆?
编辑:
这是我在 initWithFrame:
方法中使用的代码:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = UIColorFromRGB(0xdedede);
self.layer.cornerRadius = kTextFieldCornerRadius;
self.layer.borderColor = UIColorFromRGB(0xD4974C).CGColor;
self.layer.borderWidth = 3.0f;
self.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:12.0f];
[self setClipsToBounds:YES];
[self.layer setMasksToBounds:YES];
}
return self;
}
这是现在的截图:
请注意外角如预期的那样是圆的,但边框的内角是尖的而不是圆的。这就是我要解决的问题。感谢您的帮助!
最佳答案
尝试设置这个,
[txtView setClipsToBounds:YES]; //Confirms subviews are confined to the bounds of the view
[txtView.layer setMasksToBounds:YES]; //Confirms sublayers are clipped to the layer’s bounds
编辑
可能 kTextFieldCornerRadius 的值在您的情况下设置为较低。
如果我设置 kTextFieldCornerRadius = 7;
看我可以获得完美的输出。
尝试增加半径值。
关于ios - CALayer 内边框圆角半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20258278/