2014-09-19 65 views
1

我的應用程序中有一個按鈕,在iOS7上完全可見。但是當我切換到iOS8時,不會出現此按鈕的標題標籤。我只能看到按鈕周圍的邊框。 這是製作按鈕的代碼。有人能給我提供問題的線索嗎?iOS8 UIButton標題消失

UIButton *problem = [[UIButton alloc] initWithFrame:frame]; 
[problem addTarget:self action:@selector(problemButton:) forControlEvents:UIControlEventTouchUpInside]; 
problem.backgroundColor = [UIColor whiteColor]; 
[problem setTitle:NSLocalizedString(@"ReportAProblem", nil) forState:UIControlStateNormal]; 
problem.titleLabel.textColor = CUSTOM_DARK_GRAY_COLOR; 
[[problem layer] setBorderWidth:1.0f]; 
[[problem layer] setBorderColor:CUSTOM_DARK_GRAY_COLOR.CGColor]; 
problem.layer.cornerRadius = 5; 
problem.clipsToBounds = YES; 

我發現這個問題的答案,但馬上有另: 我遇到了同樣的問題,我的一些UILabels,例如:

self.label = [[UILabel alloc] initWithFrame:labelFrame]; 
self.label.numberOfLines = 1; 
self.label.adjustsFontSizeToFitWidth = YES; 
self.label.textAlignment = NSTextAlignmentCenter; 
self.label.textColor = self.textColor; 
CGFloat fontSize = self.bounds.size.height/5; 
self.label.font = [UIFont systemFontOfSize:fontSize]; 
+0

好吧,我突然發現自己的答案。我只是不得不添加'[問題setTitleColor:CUSTOM_DARK_GRAY_COLOR forState:UIControlStateNormal];'我的代碼 – Thorax 2014-09-19 12:29:10

+0

你爲什麼要設置你的視圖高度的字體大小的比例?也許用你的標籤做更有意義。 'CGFloat fontSize = self.label.bounds.size.height/5;' – Starscream 2014-09-19 12:36:59

回答

3

您應該使用- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state代替titleLabel.textColor

第二個問題:你爲什麼要設置視圖高度的比例作爲字體大小?也許用你的標籤做更有意義。 CGFloat fontSize = self.label.bounds.size.height/5;無論如何,你通常想要做的是有一個固定的字體大小,並適應它周圍的標籤框架。

+0

謝謝你的回答@Starscream。你能回答我問題的第二部分嗎? – Thorax 2014-09-19 12:36:34

+0

我編輯了我的答案 – Starscream 2014-09-19 12:39:38

+0

不幸的是,沒有解決問題。這與fontSize的破解 - 這是需要的。這不會造成問題。 – Thorax 2014-09-19 12:54:33