How to get back the UIButton border in iOS 7?

20,107

Solution 1

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]];
}

Solution 2

Try this

set border width of button by using QuartzCore Framework

#import <QuartzCore/QuartzCore.h>

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

Solution 3

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.

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

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

Share:
20,107

Related videos on Youtube

ohho
Author by

ohho

I run and write code.

Updated on July 09, 2022

Comments

  • ohho
    ohho almost 2 years

    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 .xib is "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?

    • Abdullah Md. Zubair
      Abdullah Md. Zubair over 10 years
    • ohho
      ohho over 10 years
      @AbdullahMd.Zubair it's not a duplicate. I am compiling an iOS SDK 6.1 app, not an iOS SDK 7 app.
    • iPatel
      iPatel over 10 years
      use #import <QuartzCore/QuartzCore.h> frame work and set layerBorder = 1 ;..
    • Abdullah Md. Zubair
      Abdullah Md. Zubair over 10 years
      @ohho when your app run on ios7, it gets compiled on ios7
    • mtisz
      mtisz over 9 years
  • Paul Solt
    Paul Solt about 10 years
    I prefer to set the background images using resizable images. Checkout variations of the UIButton for iOS 7 and touch behavior.