iOS Buttons - add border

IosObjective CIos7Uibutton

Ios Problem Overview


I am making my app ready for iOS7. I did conversion and was working with a user. The button in the app does not look like button. Looks very flat. Is there someway to put border or make it stand like a button?

Ios Solutions


Solution 1 - Ios

Try this for adding border, It will work

#import <QuartzCore/QuartzCore.h>

then in viewDidLoad

_btn.layer.borderWidth=1.0f;
_btn.layer.borderColor=[[UIColor blackColor] CGColor];
_btn.layer.cornerRadius = 10;

also you can fill the color for making appearance somewhat like button, or best way is to use image there

Apart from BorderColor, you can do it by using Runtime attributes too.

enter image description here

Solution 2 - Ios

try this , this will set border to button

#import <QuartzCore/QuartzCore.h>

btn.layer.borderColor = [UIColor blackColor].CGColor;

btn.layer.borderWidth = 1.0;

btn.layer.cornerRadius = 10;

Solution 3 - Ios

With Swift and XCode 6 you can do this.

Click the UIButton element in Storyboard, and go to identity inspector. In the user defined runtime attributes, enter:

layer.borderWidth number 1

If you want nice looking corners

layer.cornerRadius number 5
layer.maskToBounds boolean true

Now this will give you a border but to set the colour you need to do it with code. Go to your view controller, and add an IBOutlet from your button. Note that in this case it's an IBOutlet, not an IBAction. Say you do,

@IBOutlet weak var xButton: UIButton!

Call this in the viewDidLoad function like below to set the colour.

xButton.layer.borderColor = UIColor.whiteColor().CGColor

Thanks!

Solution 4 - Ios

The design principles in iOS7 have changed. However, if you want to go flatter, but still want a custom button that "stands like a button", you can try out this open source component collection:

FlatUIKit on GitHub

Solution 5 - Ios

There are two way to simplify button in ios 7

1>Set image : Just like Button using setImage Property for button

2>Set bordercolor borderWidth :

button.layer.borderWidth=1.0f;

button.layer.borderColor=[[UIColor blackColor] CGColor];

Solution 6 - Ios

I suggest you try one of the iOS BootstrapButton libraries (or clones). Just change UIButton in the storyboard to BButton. There is just no preview in the storyboard.

Solution 7 - Ios

If you use a background image, move button backward. Editor>Arrange>send backward

Solution 8 - Ios

In ios7 buttons are supposed to look borderless. Please see apple's View Transition Guidelines for help.

If you REALLY want the buttons to have a border, do: [button setImage:forState:] to set a customized button image with border.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1509593View Question on Stackoverflow
Solution 1 - IosMehul ThakkarView Answer on Stackoverflow
Solution 2 - IosShaik RiyazView Answer on Stackoverflow
Solution 3 - IosmtiszView Answer on Stackoverflow
Solution 4 - IosNikola KirevView Answer on Stackoverflow
Solution 5 - IosChris AlanView Answer on Stackoverflow
Solution 6 - IoscatView Answer on Stackoverflow
Solution 7 - IosNoraView Answer on Stackoverflow
Solution 8 - IosmonkeyMooView Answer on Stackoverflow