I have noticed a that a uibutton is not showing in my app when run in iOS 9 (works fine in earlier OS versions). I know several have noticed a similar issue with storyboards (<a href="https://forums.developer.apple.com/thread/14003" rel="nofollow">https://forums.developer.apple.com/thread/14003</a>), though I am not using those and am instead building my view programmatically. There is no autolayout or autoresizingmask to worry about.
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(SUG_MARGIN, self.mainView.bounds.size.height - 40 - margin, self.mainView.bounds.size.width-margin*2, 40); [button setTitle:NSLocalizedString(@"...", nil) forState:UIControlStateNormal]; button.titleLabel.font = //...; button.backgroundColor = //...; [self.mainView addSubview:button]; NSLog(@"main:%@\nadd:%@\nsuper:%@", NSStringFromCGRect(self.mainView.frame), NSStringFromCGRect(button.frame), button.superview);
That nslog shows everything set up correctly.
I have similar buttons all over the app, but this is the only one that is not appearing, which is why I am scratching my head.Answer1:
Refactored code to assign only measure frames in viewWillLayoutSubviews and it now works. strange.