How to round the corners of a button

前端 未结 15 681
隐瞒了意图╮
隐瞒了意图╮ 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:25

    Swift 4 Update

    I also tried many options still i wasn't able to get my UIButton round cornered. I added the corner radius code inside the viewDidLayoutSubviews() Solved My issue.

    func viewDidLayoutSubviews() {
            super.viewDidLayoutSubviews()
            anyButton.layer.cornerRadius = anyButton.frame.height / 2
        }
    

    Also we can adjust the cornerRadius as follows

    func viewDidLayoutSubviews() {
            super.viewDidLayoutSubviews()
            anyButton.layer.cornerRadius = 10 //Any suitable number as you prefer can be applied 
        }
    

提交回复
热议问题