简体   繁体   中英

UIButton with autolayout doesn't appear in Xcode 8

I updated Xcode from 7.1.1 to 8 just before and found that UIButton is not appearing. Before updating Xcode it worked well. I am using autolayout and tried to make round button.

My Code

btn.layer.masksToBounds = YES;
btn.layer.cornerRadius = btn.frame.size.height/2;

I tried this code, but not working for me

[self.view layoutIfNeeded];

Even I confirmed the button is visible in the Debug View Hierarchy.

Below I attached debug view hierarchy.

UIButton appears in Debug View Hierarchy

I just solved this issue.

I moved those code from viewDidLoad to viewDidAppear and it works fine.

btn.layer.masksToBounds = YES;
btn.layer.cornerRadius = btn.frame.size.height/2;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM