Ios CALayer内边界角半径

Ios CALayer内边界角半径,ios,objective-c,uitextview,calayer,Ios,Objective C,Uitextview,Calayer,我有一个UITextView,我在其中设置其图层上的边框宽度、边框颜色和角半径属性,外部看起来很棒。但是,边框的内部不像外部有圆角,看起来有点滑稽。有办法绕过边界的内角吗 编辑: 以下是我在initWithFrame:方法中使用的代码: - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = UIColorF

我有一个UITextView,我在其中设置其图层上的边框宽度、边框颜色和角半径属性,外部看起来很棒。但是,边框的内部不像外部有圆角,看起来有点滑稽。有办法绕过边界的内角吗

编辑: 以下是我在
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看我能得到完美的输出


尝试增加半径值。

导入
QuartzCore
框架并添加以下代码行:

目标-C

SWIFT-3.0.1(游乐场代码)

输出:

重要提示:


确保
拐角半径
大于
边界宽度
。否则,您将无法看到差异。

请显示您的代码和文本视图的快照。我已导入QuartzCore,并尝试更改角半径,结果成功!谢谢
UIView *yourView=[[UIView alloc]initWithFrame:CGRectMake(0, 50, 320, 430)];
yourView.layer.borderColor = [UIColor redColor].CGColor;
yourView.layer.borderWidth = 10.0f;
yourView.layer.cornerRadius = 20.0f;

[yourView setClipsToBounds:YES];
[yourView.layer setMasksToBounds:YES];
//: Playground - noun: a place where people can play

 import UIKit
 import PlaygroundSupport
 import QuartzCore

let containerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 375.0, height: 100.0))

containerView.backgroundColor = UIColor.white
containerView.layer.borderWidth = 10
containerView.layer.borderColor = UIColor.red.cgColor
containerView.clipsToBounds = true
containerView.layer.masksToBounds = true
containerView.layer.cornerRadius = 20

 PlaygroundPage.current.liveView = containerView
 PlaygroundPage.current.needsIndefiniteExecution = true