5

I've a UIViewController and I'm displaying it as UIModalPresentationPopover. It had its corner radius set to 10.0 and border width to 1.0.

- (void)viewWillLayoutSubviews {
  [super viewWillLayoutSubviews];     

  self.view.layer.borderWidth = 1.0f;
  self.view.layer.cornerRadius = 10.0f;
  self.view.layer.masksToBounds = YES;
}

It is not showing any border along corner radius and it is giving a weird effect. It was working fine before iOS10. What should I do to solve this problem?

Edit: The screenshots are as enter image description here

If i add 2 pixel border then still 1 pixel is missing from View enter image description here

Hassy
  • 5,068
  • 5
  • 38
  • 63

3 Answers3

7

Your code is good but it is missing one line,

view.clipsToBounds = true

Set this line and run again.

Hope this will help you.

batman
  • 1,937
  • 2
  • 22
  • 41
KAR
  • 3,303
  • 3
  • 27
  • 50
4

New one thing into XCode8 we can't directly set the cornerRadius of the layer.

When you want to apply cornerRadius of UIView need to add one line of code before applying cornerRadius.

yourButton.layoutIfNeeded()

Example into Objective C.

[yourButton layoutIfNeeded];
yourButton.layer.cornerRadius = yourButton.frame.size.height/2;
[[yourButton layer] setBorderWidth:2.0f];

Example into Swift3

self.layoutIfNeeded()
yourButton.layer.cornerRadius = self.frame.height / 2.0
yourButton.layer.borderWidth = 2.0
Nimit Parekh
  • 16,776
  • 8
  • 50
  • 72
  • @Are you try into XCode8? – Nimit Parekh Oct 05 '16 at 08:20
  • thank you, it worked for me. My problem was changing the cornerRadius of an imageView nested inside a custom cell. The change was made in awakeFromNib method. It seems that as of swift 3, before layout is performed all frames start with (0, 0, 1000, 1000). – andrei Oct 05 '16 at 09:40
1

i Solved my Problem by following code

if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")){
    self.view.superview.layer.cornerRadius = 15.0f;
}

I did set the view corner radius to 10.0 so 15.0 was exact value at which the superview wont meddle with its subview corner radius and borders to show it as blur or 1 pixel less.

Edit: Custom created UIViewController if animated might need to implement above code after it has finished animating.

Hassy
  • 5,068
  • 5
  • 38
  • 63