How to round the corners of a button

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

    For Swift:

    button.layer.cornerRadius = 10.0
    
    0 讨论(0)
  • 2020-12-07 07:46

    An alternative answer which sets a border too (making it more like a button) is here ... How to set rectangle border for custom type UIButton

    0 讨论(0)
  • 2020-12-07 07:48

    First set width=100 and Height=100 of button

    Objective C Solution

    YourBtn1.layer.cornerRadius=YourBtn1.Frame.size.width/2;
    YourBtn1.layer.borderColor=[uicolor blackColor].CGColor;
    YourBtn1.layer.borderWidth=1.0f;
    

    Swift 4 Solution

    YourBtn1.layer.cornerRadius = YourBtn1.Frame.size.width/2
    YourBtn1.layer.borderColor = UIColor.black.cgColor
    YourBtn1.layer.borderWidth = 1.0
    
    0 讨论(0)
提交回复
热议问题