user2779450
user2779450

Reputation: 775

Xcode 5 Round Rect Buttons

I have an app that incorporates many round rect buttons. However, in xcode 5, those dont exist. How do I get the round rect buttons back? They are essential to my app. Now it just is pressable text. What do I do? I am planning on releasing this app later, if that is relevant.

Upvotes: 52

Views: 65712

Answers (7)

Sandu
Sandu

Reputation: 516

In Swift 3: we can added it viewdidload

  button.layer.cornerRadius = 0.5*button.bounds.size.width
  button.clipsToBounds = true

Upvotes: 1

Matthew Korporaal
Matthew Korporaal

Reputation: 2384

  1. Open the storyboard and choose the button you want to change.
  2. Open the Identity Inspector in the Utility Panel (right panel, 3rd button on top).
  3. Add (+) a new User Defined Runtime Attribute -- Key Path: layer.cornerRadius, Type: Number, Value: {integer}.

The higher the number, the more rounded the corners. 50 is a circle for a standard button (or width/2). You won't see the change in the storyboard, but it will show at runtime.

Screenshot of added attribute

Upvotes: 154

Syed Uzair Ahmed
Syed Uzair Ahmed

Reputation: 145

Click on the button you want to get rounded. Then click on the Identity Inspector on the right top side. There You can see User Defined Runtime Attributes. Click on plus (+)

see image

You wont see the changes in View. You will see it in Runtime

Upvotes: 3

Alvin George
Alvin George

Reputation: 14296

Swift 2.0:

let sampleButton = UIButton(frame: CGRectMake(100,100,200,100))
  sampleButton.titleLabel?.text = "SAMPLE"
  sampleButton.backgroundColor = UIColor.grayColor()

  //Setting rounded boarder
  sampleButton.layer.cornerRadius = 10
  sampleButton.layer.borderWidth = 1
  sampleButton.layer.borderColor = UIColor.blackColor().CGColor

  self.view.addSubview(sampleButton)

Upvotes: 3

Avijit Nagare
Avijit Nagare

Reputation: 8782

Same can achieved by programmatically.where myView is IBOutlet object.

myView.layer.cornerRadius = 5;
myView.layer.masksToBounds = YES;

Upvotes: 3

Robert
Robert

Reputation: 5302

Here's a similar answer to the one I gave to this question:

-EDIT-
Add: #import <QuartzCore/QuartzCore.h> to the top of your .h file.

If you want rounded corners 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];

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:

enter image description here

Upvotes: 10

CSmith
CSmith

Reputation: 13458

Set a background image on your buttons with the desired borders, using a stretchable image.

Check this link for a good example: Stretch background image for UIButton

OR, embrace the new iOS7 UI and scrap the borders ... ;-)

Upvotes: 3

Related Questions