No Round Rect Button in Xcode 5?

喜夏-厌秋 提交于 2019-11-28 03:56:50

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

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

Select Background and change it to White:

If you want rounded corners you can do so with a little bit of code. Just ctrl-drag from the button to your .h file, call it something like roundedButton and add this in your viewDidLoad:

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

Can also make the rounded rect within the storyboard.

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...".

Confirming that it definitely has been 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.

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

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

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.

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

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

if you want to set the border width

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

you can also give the color for border

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!