ios Xcode 5 中没有圆角矩形按钮?

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

No Round Rect Button in Xcode 5?

iosuibuttoninterface-builderios7xcode5

提问by juminoz

Is drag and drop of round rect button no longer available in Xcode 5? I can't seem to find it in the Interface Builder. I was guessing that this is one of the changes in iOS 7, but I just wanted to make sure.

Xcode 5 中不再提供圆形矩形按钮的拖放功能吗?我似乎无法在 Interface Builder 中找到它。我猜测这是 iOS 7 中的变化之一,但我只是想确定一下。

回答by DogCoffee

Can also make the rounded rect within the storyboard.

也可以在故事板内制作圆角矩形。

enter image description here

在此处输入图片说明

回答by Robert

The Round Rectbutton from Xcode 4 and previous versions appears to have been replaced with the System Defaultbutton, which also happens to be clear. I.e. by default there is no white background with rounded corners, only the text is visible.

Round Rect在Xcode 4和之前的版本按钮似乎已被替换的System Default按钮,这也恰好是清楚的。即默认情况下没有带圆角的白色背景,只有文本可见。

To make the button white (or any other colour), select the attributes inspector and scroll down to the Viewsection:

要使按钮变为白色(或任何其他颜色),请选择属性检查器并向下滚动到该View部分:

enter image description here

在此处输入图片说明

Select Backgroundand change it to White:

选择Background并将其更改为白色:

enter image description here

在此处输入图片说明

If you want rounded corners you can do so with a little bit of code. Just ctrl-dragfrom the button to your .hfile, call it something like roundedButtonand add this in your viewDidLoad:

如果你想要圆角,你可以用一点代码来实现。只需ctrl-drag从按钮到您的.h文件,将其命名为类似roundedButton并将其添加到您的viewDidLoad

CALayer *btnLayer = [roundedButton layer];
[btnLayer setMasksToBounds:YES];
[btnLayer setCornerRadius:5.0f];

回答by transistor1

This was too long for a comment in @Robert's answer, but I just wanted to add regarding the statement: "The Round Rect button from Xcode 4...appears to have been replaced...".

这对于@Robert 的回答中的评论来说太长了,但我只想补充一下声明:“Xcode 4 中的 Round Rect 按钮......似乎已被替换......”。

Confirming that it definitely hasbeen replaced:

确认它确实被替换:

The rounded rectangle button is deprecated in iOS 7. Instead, use a system button—that is, a UIButton object of type UIButtonTypeSystem.

iOS 7 system buttons don't include a bezel or a background appearance. A system button can contain a graphical symbol or a text title, and it can specify a tint color or receive its parent's color.

...

If you need to display a button that includes a bezel, use a button of type UIButtonTypeCustom and supply a custom background image.

iOS 7 中不推荐使用圆角矩形按钮。而是使用系统按钮,即 UIButtonTypeSystem 类型的 UIButton 对象。

iOS 7 系统按钮不包括边框或背景外观。系统按钮可以包含图形符号或文本标题,并且可以指定色调颜色或接收其父级的颜色。

...

如果需要显示包含边框的按钮,请使用 UIButtonTypeCustom 类型的按钮并提供自定义背景图像。

Apple iOS 7 Transition Guide, p. 45, "Rounded Rectangle Button"

Apple iOS 7 过渡指南,第 1 页。45、《圆角矩形按钮》

So, Apple's recommendation is to use a background image.

因此,Apple 的建议是使用背景图像。

回答by user3675855

Actually in ios 7 the total UI has been changed for basic controls. If still you want to have a rounded rect button, you have to go for the coregraphical property of UIView subclasses i.e; layer property.

实际上,在 ios 7 中,基本控件的总 UI 已更改。如果你仍然想要一个圆形的矩形按钮,你必须使用 UIView 子类的 coregraphical 属性,即;层属性。

buttonObj.layer.cornerRadius = 5.0f;//any float value

buttonObj.layer.cornerRadius = 5.0f;//any float value

to show the effect you have to give some background color to buttonObj

要显示效果,您必须为 buttonObj 提供一些背景颜色

if you want to set the border width

如果要设置边框宽度

buttonObj.layer.borderWidth = 2.0f;//any float value

buttonObj.layer.borderWidth = 2.0f;//any float value

you can also give the color for border

你也可以给边框的颜色

buttonObj.layer.borderColor = [[UIColor greenColor]CGColor];

buttonObj.layer.borderColor = [[UIColor greenColor]CGColor];

Note: Here we have to use CGColor for the layers because layers are the core graphical properties of UIViews

注意:这里我们必须使用 CGColor 作为图层,因为图层是 UIViews 的核心图形属性