ios - CALayer 内边框圆角半径

标签 ios objective-c uitextview calayer

我有一个 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; 看我可以获得完美的输出。

enter image description here

尝试增加半径值。

关于ios - CALayer 内边框圆角半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20258278/

相关文章:

ios - 使用 Realm Mobile Platform 处理照片

ios - iOS 上的 CSS 3.0 动画

ios - 如何更新 spotify session ?

ios - dyld:dyld_sim与mach-o xcode 9.0不兼容

iphone - 关于运送 iphone 应用程序的安全问题

ios - 使用 splitViewController :willChangeToDisplayMode: in iOS8 时如何显示 barButtonItem

uiscrollview - UITextView 在 iOS 8 中隐藏键盘时滚动到顶部

ios - 多个项目和 Cocoapods

ios - TextView 第一次没有正确格式化文本,但第二次可以

ios - 突出显示 uitextview 显示 inputAccessoryView