2011-02-04 51 views
3

我已經看遍了所有的堆棧溢出,爲這個問題的答案,我只能找到4.1和以下的工作方式,但對於4.2.1和以上,我無法找到一個新的獲取ON和OFF文本的方式改變。是否有改變可以說是和的方式 號這是我目前:另一個自定義的UISwitch問題

UISwitch *switchControl = [[UISwitch alloc] initWithFrame:frame]; 
    [switchControl addTarget:self action:action forControlEvents:UIControlEventValueChanged]; 
    switchControl.backgroundColor = [UIColor clearColor]; 
    switchControl.on = value; 
    [cell addSubview:switchControl]; 
    [switchControl release]; 

會有什麼改變UISwitch文本的最簡單的方法?或者,如果我製作兩幅圖像並使用動畫使它們流動,它會更容易,就像它是一個普通的UISwitch。

回答

1

我寫了一個自定義開關類。希望這可以幫助。 http://cl.ly/4OQN

編輯: 此外,也許試試這個:

switchView = [[UICustomSwitch alloc] initWithFrame:CGRectZero]; 
[switchView setCenter:CGPointMake(160.0f,260.0f)]; 
[switchView setLeftLabelText: @"Foo"]; 
[switchView setRightLabelText: @"Bar"]; 
[[switchView rightLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]]; 
[[switchView leftLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]]; 
[[switchView leftLabel] setTextColor:[UIColor yellowColor]];