How to round the corners of a button

前端 未结 15 694
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 06:54

I have a rectangle image (jpg) and want to use it to fill the background of a button with rounded corner in xcode.

I wrote the following:

UIButton *b         


        
15条回答
  •  心在旅途
    2020-12-07 07:24

    Try my code. Here you can set all properties of UIButton like text colour, background colour, corner radius, etc.

    extension UIButton {
        func btnCorner() {
            layer.cornerRadius = 10
            clipsToBounds = true
            backgroundColor = .blue
        }
    }
    

    Now call like this

    yourBtnName.btnCorner()
    

提交回复
热议问题