Xcode 8 - Removing Some Buttons

I just updated my Xcode ver from 7.3 to 8.0, and some button borders have disappeared.

The code looks great, so I really don't know what happened to the layers. btw - in some other controllers I see layer boundaries.

self.button.layer.borderColor = borderColor.CGColor; self.button.layer.borderWidth = 2; self.button.layer.cornerRadius = CGRectGetHeight(self.button.frame) / 2; 

before: (Image for example only - borders look different in real time)

before:

Now:

now:

+8
ios iphone xcode xcode8 uibutton
source share
6 answers

The reason is that Xcode 8 introduces a new way to scale storyboards.

Prior to Xcode 8, in the life cycle of the view controller, frames were not known in viewDidLoad (or in didSet properties). You should have waited for viewDidLayoutSubviews (when Autolayout finished applying restrictions to define frames for each subview in the main view. But bounds were available before that: they were just set to the size of the IBOutlet in the storyboard.

In Xcode 8, everything is different: because of their new scaling system, even bounds tags are incorrect before ViewDidLayoutSubviews (they can exist, but with dummy values ​​like 1000 x 1000).

Finally:

  • you can use things like cornerRadius in viewDidLoad or in IBOutlet didSet if you use a fixed value
  • if you need to define your cornerRadius based on bounds and then do it in viewDidLayoutSubviews or use NSLayoutConstraints (their value is fixed and known from Autolayout)
  • if you need to use cornerRadius in views (e.g. subclasses of UITableViewCell or UICollectionViewCell), you can either do it in layoutSubviews (but then you need to specify either a fixed value or an NSLayoutConstraint constant in cornerRadius) or awakeFromNib (in this case, just add self.layoutIfNeeded before doing something related to a frame or kin to make the cell count the frame of its subtasks).
+16
source share

I think the problem is in it:

 CGRectGetHeight(self.button.frame) / 2; 

When you set the angle, I think that the height button does not matter or the value for a larger border will not be displayed. You can try changing it to

 self.button.layer.cornerRadius = 15; 

If the job is, I think you can check your logic and set it when the height button gets the correct value.

+4
source share

Try this and check:

 #import <QuartzCore/QuartzCore.h> self.button.layer.borderColor = [UIColor whiteColor].CGColor; self.button.layer.borderWidth = 2; self.button.layer.cornerRadius = 5; // Change this value on your requirement self.button.clipsToBounds = YES; 
+2
source share

To calculate the viewing frame, you can try with layoutIfNeeded. For example, for a label in a UITableViewCell:

 override func awakeFromNib() { super.awakeFromNib() self.layoutIfNeeded() self.qualityIndexLabel.makeRound() } 
0
source share

use dispatch_after

 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ self.button.layer.borderColor = borderColor.CGColor; self.button.layer.borderWidth = 2; self.button.layer.cornerRadius = CGRectGetHeight(self.button.frame) / 2; }); 
0
source share

RoundedRect is deprecated using the UIButtonTypeSystem. see https://developer.apple.com/reference/uikit/uibutton?language=objc for more information.

-one
source share

All Articles