剪辑按钮查看
Clip button to view
enter image description here所以我有 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
}
}
在此视图中有圆角,但按钮没有那些圆角
我该如何实施? (所以那个按钮也有圆角。
我有两个按钮,所以我只想要左按钮的左角和右按钮的右角。
我已经添加了我想要实现的图像link。
请尝试使用 masksToBounds
属性,
@IBOutlet weak var firstbutton: UIButton!{
didSet{
proceedButton.clipsToBounds = true
proceedButton.masksToBounds = true
}
}
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.
}
}
添加以下约束
输出:
这可能对您有所帮助:)
enter image description here所以我有 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
}
}
在此视图中有圆角,但按钮没有那些圆角 我该如何实施? (所以那个按钮也有圆角。 我有两个按钮,所以我只想要左按钮的左角和右按钮的右角。
我已经添加了我想要实现的图像link。
请尝试使用 masksToBounds
属性,
@IBOutlet weak var firstbutton: UIButton!{
didSet{
proceedButton.clipsToBounds = true
proceedButton.masksToBounds = true
}
}
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.
}
}
添加以下约束
输出:
这可能对您有所帮助:)