首页 > 解决方案 > 应用自定义遮罩时 UITextfield 的断角

问题描述

我正在尝试创建一个左角四舍五入的文本字段。为此,我使用以下代码来应用屏蔽。现在文本字段的角被修剪掉了。知道为什么吗?

    let shape = CAShapeLayer()
    shape.bounds = textfieldContainerView.frame
    shape.position = textfieldContainerView.center
    shape.path = UIBezierPath(roundedRect: textfieldContainerView.bounds,
                              byRoundingCorners: [.topLeft, .bottomLeft],
                              cornerRadii: CGSize(width: 5, height: 5)).cgPath
    textfieldContainerView.layer.mask = shape
    textfieldContainerView.layer.borderColor = ColorKit.smoke.cgColor
    textfieldContainerView.layer.borderWidth = 2.0

这是它的样子(注意左边的破角)。

在此处输入图像描述

标签: iosswiftxcodeuitextfieldcashapelayer

解决方案


这适用于较低的半径和高度值,例如 4。此外,折角高度随着半径/高度值的增加而继续增加


推荐阅读