ios 如何在 Xcode 6 中向故事板添加带边框的按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30091577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 05:55:42  来源:igfitidea点击:

How to add a button with border to storyboard in Xcode 6

iosobjective-cxcodeios8xcode6

提问by James

I wanna create a button with border in Xcode 6. For instance, I want it to look like the buttons from this library - https://github.com/a1anyip/AYVibrantButton- without any special visual effects. Is it possible to achieve this by doing some setup in IB without writing any code? Thanks.

我想在 Xcode 6 中创建一个带边框的按钮。例如,我希望它看起来像这个库中的按钮 - https://github.com/a1anyip/AYVibrantButton- 没有任何特殊的视觉效果。是否可以通过在 IB 中进行一些设置而不编写任何代码来实现这一点?谢谢。

回答by Leo

You can add Runtime Attribute in storyboard

您可以在故事板中添加运行时属性

select your button

选择你的按钮

Runtime Attribute in storyboard

故事板中的运行时属性

回答by James

"addImageButton" here is my UIButton and I am using below lines of code to create border to the button.

“addImageButton”这里是我的 UIButton,我使用下面的代码行来创建按钮的边框。

 [addImageButton.layer setBorderWidth:5];
[addImageButton.layer setBorderColor:[[UIColor redColor] CGColor]];
[addImageButton setTintColor:[UIColor whiteColor]];
[addImageButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

Snapshot

快照

Hope this solves your issue.

希望这能解决您的问题。