【问题标题】:Clip button to view剪辑按钮以查看
【发布时间】:2019-05-23 16:51:51
【问题描述】:

enter image description hereSo 我有 backgroundView (UIView) 和两个按钮。 现在我制作了以下代码

 buttonBackgroundView.layer.cornerRadius = 5.0
 buttonBackgroundView.layer.borderColor = UIColor.black.cgColor
 buttonBackgroundView.layer.borderWidth = 0.5

@IBOutlet weak var firstbutton: UIButton!{
        didSet{
            proceedButton.clipsToBounds = true
        }
    }

在此视图有圆角,但按钮没有圆角 我该如何实施? (所以那个按钮也有圆角。 我有两个按钮,所以我只想要左按钮的左角和右按钮的右角。

我已经添加了我想要实现的图片链接。

【问题讨论】:

  • 不是一个明确的问题。请说明。
  • 您想将视图屏蔽到边界,而不是按钮。在视图层上试试这个。 developer.apple.com/documentation/quartzcore/calayer/…
  • 您需要将父视图的 maskToBounds 设置为 True 而不是按钮。或者您可以正确设置按钮的图层属性和 maskToBounds。

标签: ios iphone uibutton swift4


【解决方案1】:

请尝试使用masksToBounds 属性,

@IBOutlet weak var firstbutton: UIButton!{
    didSet{
        proceedButton.clipsToBounds = true
        proceedButton.masksToBounds = true
    }
}

【讨论】:

  • 已解决。感谢您的帮助
【解决方案2】:
class ViewController: UIViewController {

    @IBOutlet weak var yourView: UIView! //Create your view outlet
    override func viewDidLoad() {
        super.viewDidLoad()
        yourView.clipsToBounds = true
        yourView.layer.cornerRadius = 15 // As per you requirement 
        yourView.layer.borderColor = UIColor.black.cgColor
        yourView.layer.borderWidth = 2

        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

添加以下约束

输出:

这可能对你有帮助:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-29
    • 1970-01-01
    相关资源
    最近更新 更多