如何在 iOS 7 中找回 UIButton 边框?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19509250/
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 02:29:14  来源:igfitidea点击:

How to get back the UIButton border in iOS 7?

iosxcodeuibuttonxcode5

提问by ohho

I built an old project in iOS SDK 6.1 in Xcode 5. However, the UIbutton is borderless when the app runs on an iPhone running iOS 7. I have checked the .xibis "Builds for" > "Project Deployment Target (5.0)":

在 Xcode 5 的 iOS SDK 6.1 中构建了一个旧项目。但是,当应用程序在运行 iOS 7 的 iPhone 上运行时,UIbutton 是无边框的。我检查了.xib“Builds for”>“Project Deployment Target (5.0)”:

enter image description here

在此处输入图片说明

How can I config Xcode 5 to build the project to show an iOS 6.1-style UIButton?

如何配置 Xcode 5 来构建项目以显示 iOS 6.1 样式的 UIButton?

采纳答案by Vaibhav Saran

you can create a category:

您可以创建一个类别:

- (void)setRoundedBorder:(float) radius borderWidth:(float)borderWidth color:(UIColor*)color
{
    CALayer * l = [self layer];
    [l setMasksToBounds:YES];
    [l setCornerRadius:radius];
    // You can even add a border
    [l setBorderWidth:borderWidth];
    [l setBorderColor:[color CGColor]];
}

回答by Kalpesh

Try this

尝试这个

set border width of button by using QuartzCoreFramework

使用QuartzCore框架设置按钮的边框宽度

#import <QuartzCore/QuartzCore.h>

button.layer.borderWidth=1.0f;
button.layer.borderColor=[[UIColor blackColor] CGColor];

回答by Fábio Oliveira

If you don't want to introduce any of the iOS 7 changes changing the SDK is not enough. You shouldn't leave the Interface Builder "Opens in" property unchanged as well.

如果您不想引入任何 iOS 7 更改,更改 SDK 是不够的。您也不应该让 Interface Builder 的“Opens in”属性保持不变。

I leave mine in "Xcode 4.6" and everything looks as it should.

我将我的留在“Xcode 4.6”中,一切看起来都应该如此。

I think the only advantage you would take is with the new auto-layout.

我认为您可以利用的唯一优势是新的自动布局。