1

In my iPhone app i have profile pic button which should be round corner always.Right now if i will give corner radius some value ,button is not round cornered in iPhone 6plus.So is there any specific general way to make this work ? Thanks in advance...

veebha
  • 47
  • 1
  • 9
  • 2
    Please post your code so we can understand that what you want to do? – BKjadav Aug 12 '15 at 09:47
  • Can u try like this http://stackoverflow.com/questions/31846476/how-to-create-a-rounded-rectangle-label-in-xcode-7-and-swift-2/31846658#31846658 – Laky Aug 12 '15 at 09:56
  • Currently yourUIButton.layer.cornerRadius = 8.0; works for one mobile screen lets say iPhone 5c. I want it to be circle in all device screens....This is the problem i am unable to resolve ... – veebha Aug 19 '15 at 10:42

3 Answers3

5

If size of the button (width, height) are same in all screen sizes then setting cornerRadius once should work, if its different in different screen sizes then do something like this, add button as property and then override viewDidLayoutSubviews method of view controller class

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    self.button.layer.cornerRadius = self.button.bounds.size.height / 2;
}
Adnan Aftab
  • 14,377
  • 4
  • 45
  • 54
  • or if it's not a UIVIewController and instead it's a UIView then you can just put this code into the `override func layoutSubviews()`... – mfaani Oct 16 '17 at 19:50
1

Take half of height of bounds and set it as radius.

self.button.layer.cornerRadius = self.button.bounds.size.height / 2;
Jakub
  • 13,712
  • 17
  • 82
  • 139
lonka
  • 11
  • 2
0

How to make round corner button which supports all device in iOS

yourUIButton.layer.masksToBounds = YES;
yourUIButton.layer.cornerRadius = 8.0;

Also in your "m" or "h" file import: #import QuartzCore/QuartzCore.h

BKjadav
  • 543
  • 2
  • 16