简体   繁体   English

按钮上的半透明边框

[英]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) (更改值使其看起来不错,alpha使其变为半透明)

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: 编辑:正如@holex建议,一种更好的方法来计算cornerRadius是:

CGFloat radius = MIN(yourButton.frame.size.width, yourButton.frame.size.height) / 2.0
yourButton.layer.cornerRadius = radius;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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