UIButton with Custom border colour, iPhone

后端 未结 5 1684
离开以前
离开以前 2021-02-04 04:47

I want to create Custom UIButton with rectangular shape. for this I am using rectangular view as a Background for UIButton and making UIbuttons background colour as clearcolor.

相关标签:
5条回答
  • 2021-02-04 05:00

    I wasted a few minutes and got frustrated that the border was not showing up even though I was setting the layer property as suggested above.

    When I set the width using the following, I saw the button border.

    [[button layer] setBorderWidth:2.0f];
    
    0 讨论(0)
  • 2021-02-04 05:00

    You can set the border properties on the CALayer by accessing the layer property of the button.

    Add Quartz

    #import <QuartzCore/QuartzCore.h>
    

    Set properties of the button:

    [[myButton layer] setBorderWidth:2.0f];
    [[myButton layer] setBorderColor:[UIColor AnyColor].CGColor];
    
    0 讨论(0)
  • 2021-02-04 05:08
      button.layer.borderColor = UIColor.orangeColor().CGColor
    

    swift example for orange border

    0 讨论(0)
  • 2021-02-04 05:11

    Try this:

        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button.layer setBorderColor:[[UIColor clearColor] CGColor]];
    

    but don't forget to add in your .h or .m file

    #import <QuartzCore/QuartzCore.h>
    
    0 讨论(0)
  • 2021-02-04 05:19

    You should set type of your UIButton to Custom, not Rounded Rect (if you are creating button via IB).

    If you are creating UIButton programmatically then you this code:

    UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
    

    And after that you can make your own customizations.

    0 讨论(0)
提交回复
热议问题