简体   繁体   中英

Semi-transparent border on button

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

纽扣

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?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM