Ios 按钮上的半透明边框
我正在尝试制作一个如下所示的按钮: 这个按钮坏了Ios 按钮上的半透明边框,ios,objective-c,uibutton,transparent,Ios,Objective C,Uibutton,Transparent,我正在尝试制作一个如下所示的按钮: 这个按钮坏了 透明背景色 不透明标题 半透明白色边框颜色 最好的方法是什么?我知道如何实现前两项,但如何获得半透明白色边框颜色?使用按钮的图层属性: 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; (更
- 透明背景色
- 不透明标题
- 半透明白色边框颜色
最好的方法是什么?我知道如何实现前两项,但如何获得半透明白色边框颜色?使用按钮的图层属性:
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;
(更改值使其看起来良好,alpha使其半透明)
此外,如果您还没有圆,则需要:
yourButton.layer.cornerRadius = yourButton.frame.size.width/2;
编辑:正如@holex所建议的,计算拐角半径的更好方法是:
CGFloat radius = MIN(yourButton.frame.size.width, yourButton.frame.size.height) / 2.0
yourButton.layer.cornerRadius = radius;
yourButton.frame.size.width/2
仅在按钮为正方形时适用。我会计算拐角半径:CGFloat\u radius=MIN(yourButton.frame.size.width,yourButton.frame.size.height)/2.0代码>可以随时为按钮设置半透明边框。