18

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. But border of UIbutton still remains. any suggestions on how to make border disappear? Thanks for any help in advance..

alekhine
  • 1,600
  • 4
  • 20
  • 45
  • Might be a duplicate of http://stackoverflow.com/questions/2808888/is-it-even-possible-to-change-a-uibuttons-background-color. Check that question out. – Jamison Dance Sep 09 '11 at 05:31
  • This is not a duplicate of the ref you gave... they are discussing background color where as he is asking for border color. – Prabh Sep 09 '11 at 05:39
  • Might be a duplicate of http://stackoverflow.com/questions/8162411/how-to-create-border-in-uibutton Best of luck – Ayaz Apr 29 '13 at 05:41

5 Answers5

41

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>
Prabh
  • 2,466
  • 2
  • 24
  • 27
13

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];
Madhav Sbss
  • 325
  • 2
  • 7
5
  button.layer.borderColor = UIColor.orangeColor().CGColor

swift example for orange border

Elazaron
  • 476
  • 11
  • 21
2

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];
EFE
  • 3,732
  • 4
  • 22
  • 30
Rajput V.K
  • 63
  • 1
  • 6
0

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.

Nekto
  • 17,837
  • 1
  • 55
  • 65