0

I'm trying to make a button that looks like this:

Button

The button has

  • transparent background color
  • non-transparent title
  • semi-transparent white border color

What's the best way to do this? I know how to achieve the first two items, but how do I get the semi-transparent white border color?

helloB
  • 3,472
  • 10
  • 40
  • 87

1 Answers1

0

Use the button's layer's properties:

yourButton.layer.borderWidth = 3.0f;
yourButton.layer.borderColor = [UIColor colorWithRed:178/255.0 green:170/255.0 blue:156/255.0 alpha:0.4].CGColor;

(Change the values so it looks good, alpha makes it semi-transparent)

Also, you'll need this if you don't have the circle yet:

yourButton.layer.cornerRadius = yourButton.frame.size.width/2;

EDIT: As @holex suggested, a better way to calculate the cornerRadius is:

CGFloat radius = MIN(yourButton.frame.size.width, yourButton.frame.size.height) / 2.0
yourButton.layer.cornerRadius = radius;
Dante Puglisi
  • 648
  • 7
  • 24
  • `yourButton.frame.size.width/2` only applies if your button is squared. – Dante Puglisi Mar 15 '16 at 16:44
  • 1
    I would go for calculating the corner radius: `CGFloat _radius = MIN(yourButton.frame.size.width, yourButton.frame.size.height) / 2.0;` – holex Mar 15 '16 at 16:50