2015-10-06 46 views
0

我注意到,在iOS 9中運行時,我的應用程序中沒有顯示uibutton(在早期操作系統版本中正常工作)。我知道幾個人已經注意到與故事板類似的問題(https://forums.developer.apple.com/thread/14003),雖然我沒有使用這些,而是​​以編程方式構建我的視圖。沒有自動佈局或autoresizingmask擔心。iOS 9查看不出現

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); 

那的NSLog顯示一切設置正確。

我在應用程序中有類似的按鈕,但這是唯一沒有出現的按鈕,這就是爲什麼我抓撓我的頭。

+2

這段代碼在ViewDidLoad中? – KrisJones

+0

它是在viewWillAppear –

回答

0

重構的代碼在viewWillLayoutSubviews中僅分配度量值框,現在可以使用。奇怪。

+0

@肖恩弗雷澤我面臨的問題,請檢查此鏈接http://stackoverflow.com/questions/33936634/uibutton-is-not-appear-on-view-in-ios-9 – VJVJ