2012-11-27 24 views
0

我在全局設置所有UISegmentedControl的外觀。但是我注意到,當我這樣做時,它打破了禁用狀態。UISegmentedControl的設置外觀中斷禁用狀態

下面是代碼,我必須改變titleTextAttributes

NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: 
           [UIFont boldSystemFontOfSize:12], UITextAttributeFont, 
           [UIColor whiteColor], UITextAttributeTextColor, 
           [UIColor colorWithRed:0x49/255.0 green:0x49/255.0 blue:0x49/255.0 alpha:1], UITextAttributeTextShadowColor, 
           [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset, 
           nil]; 
[[UISegmentedControl appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal]; 

現在這個偉大工程,所有分段控制器更新。

但我用setEnabled:forSegmentAtIndex禁用的項目不再被禁用,並且可點擊。爲什麼會發生?我如何讓他們再次被禁用。我試圖將它應用到殘疾人狀態,但它不起作用。

[[UISegmentedControl appearance] setTitleTextAttributes:attributes forState:UIControlStateDisabled]; 

回答

0

那麼它看起來設置爲UISegmentedControl一個全球性的出現是不是最好的方法,因爲它不兌現UIControlStateDisabled。

我以爲我不得不使用UIControlStateDisabled,因爲沒有任何工作,但似乎設置背景直接工作。所以我剛剛結束了一個UISegmentedControlExtended類的初始化背景,現在setEnabled函數正常工作。

+0

我有這個確切的問題。你能否更詳細地解釋你做了什麼?謝謝。 – pizzafilms