ios - UITextField 没有圆边

标签 ios objective-c uitextfield

我用它来圆我的 UITextFeild 的顶部两个角

 CAShapeLayer * maskLayer = [CAShapeLayer layer];
maskLayer.path = [UIBezierPath bezierPathWithRoundedRect: self.emailFeild.bounds byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii: (CGSize){10.0, 10.}].CGPath;

我还为这个 UITextField 添加了边框

 self.emailFeild.layer.borderColor = [[self colorFromHexString:@"0x3263A3"]CGColor];
self.emailFeild.layer.borderWidth = 1.0f;
self.emailFeild.layer.mask = maskLayer;

但是当我运行它时。它没有绕过边界的角落,我得到了这个结果 enter image description here

最佳答案

mask 层不会被绘制,只是用于计算 mask 。尝试:

-(void)roundCorners:(UIRectCorner)corners radius:(CGFloat)radius
{
    CGRect bounds = self.bounds;
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bounds
                                                   byRoundingCorners:corners
                                                         cornerRadii:CGSizeMake(radius, radius)];

    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = bounds;
    maskLayer.path = maskPath.CGPath;

    self.layer.mask = maskLayer;

    CAShapeLayer*   frameLayer = [CAShapeLayer layer];
    frameLayer.frame = bounds;
    frameLayer.path = maskPath.CGPath;
    frameLayer.strokeColor = [UIColor redColor].CGColor;
    frameLayer.fillColor = nil;

    [self.layer addSublayer:frameLayer];
}

-(void)roundTopCornersRadius:(CGFloat)radius
{
    [self roundCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) radius:radius];
}

关于ios - UITextField 没有圆边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39335757/

相关文章:

objective-c - Javascript 到 Obj-c 请求.. 将值返回给 Javascript

ios - 如何从我的iOS应用中删除推送通知?

ios - 无法在 UITextField 中移动光标

ios - 通过-weak_library 弱链接静态库

ios - 如何从 UITableViewController 到多个 View Controller

ios - 您可以在 iOS 应用程序中全局禁用旋转吗?

objective-c - 在MetalKit应用程序中处理输入事件

iOS:调用方法的 UITableViewCell 中的 UITextField

objective-c - iPhone : how to decrease no. 当在 UITextField 中输入文本时依赖 UILabel

iOS - 尝试读取 bundle.man.url 时不返回任何内容