如何更改UIActionSheet按鈕顏色的顏色?UIActionSheet按鈕的顏色
16
A
回答
34
的iOS 8(UIAlertController)
這是超級簡單的做,如果您使用的是UIAlertController。只需更改UIAlertController視圖上的色調顏色即可。
[alertController.view setTintColor:[UIColor red];
的iOS 7(UIActionSheet)
我通過使用這種簡單的方法成功改變文本的顏色。
- (void) changeTextColorForUIActionSheet:(UIActionSheet*)actionSheet {
UIColor *tintColor = [UIColor redColor];
NSArray *actionSheetButtons = actionSheet.subviews;
for (int i = 0; [actionSheetButtons count] > i; i++) {
UIView *view = (UIView*)[actionSheetButtons objectAtIndex:i];
if([view isKindOfClass:[UIButton class]]){
UIButton *btn = (UIButton*)view;
[btn setTitleColor:tintColor forState:UIControlStateNormal];
}
}
}
確保運行此後你叫
[actionSheet showInView];
如果你之前[showInView]調用它,所有的按鈕,但取消按鈕將被着色。希望這可以幫助別人!
1
不幸的是,沒有使用未記錄的API,沒有官方的方法來改變UIActionSheet上的按鈕顏色。如果您繼承UIActionSheet控件,您可能可以自定義這個。
見這個例子:http://blog.corywiles.com/customizing-uiactionsheet-buttons
7
我已經創建了子類UICustomActionSheet,允許自定義字體,顏色和內部UIActionSheet按鈕的圖像。這絕對是AppStore的安全,你可以下一個鏈接上找到這個類的代碼:
https://github.com/gloomcore/UICustomActionSheet
享受吧!
1
我們可以使用背景圖像來做到這一點。我認爲這是最簡單的方法。
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Actionsheet" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[actionSheet addButtonWithTitle:@"Button 1"]; //Blue color
[actionSheet addButtonWithTitle:@"Button 2"];
[actionSheet addButtonWithTitle:@"Cancel"];
[actionSheet addButtonWithTitle:nil];
[actionSheet setCancelButtonIndex:2];
[actionSheet setDestructiveButtonIndex:1];
[actionSheet showInView:self.view];
UIButton *button = [[actionSheet subviews] objectAtIndex:1];
UIImage *img = [button backgroundImageForState:UIControlStateHighlighted];//[UIImage imageNamed:@"alert_button.png"];
[button setBackgroundImage:img forState:UIControlStateNormal];
0
您可以輕鬆地通過使用下面的代碼
蘋果
UIActionSheetDelegate
協議文檔
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
for (UIView *_currentView in actionSheet.subviews)
{
if ([_currentView isKindOfClass:[UIButton class]])
{
UIButton *button = (UIButton *)_currentView;
[button setTitleColor:YOUR_COLOR forState:UIControlStateNormal];
}
}
}
相關問題
- 1. UIActionSheet按鈕顏色問題
- 2. 如何更改UIActionsheet按鈕的顏色?
- 3. 自定義顏色到UIActionsheet按鈕
- 4. 如何設置UIActionSheet按鈕顏色
- 5. Objective C UIActionSheet自定義按鈕顏色
- 6. 更改UIActionSheet按鈕背景顏色和按鈕字體
- 7. 使綠色UIActionSheet按鈕?
- 8. 如何更改UIActionSheet中按鈕的突出顯示顏色 - iPad
- 9. iOS7自定義按鈕與UIActionSheet褪色
- 10. UIActionsheet背景清除顏色
- 11. UINavigationBar按鈕顏色
- 12. 按鈕顏色WPF
- 13. UIActionSheet動態按鈕
- 14. 更改顏色的按鈕
- 15. 切換按鈕的顏色
- 16. 帶禁用按鈕的UIActionSheet?
- 17. UIActionSheet中的撤消按鈕
- 18. 更改UIActionSheet iOS的背景顏色?
- 19. 更新按鈕顏色
- 20. Android按鈕邊框顏色
- 21. IBAction按鈕更改顏色?
- 22. 切換按鈕顏色VB.net?
- 23. 按鈕顏色錯誤
- 24. jQueryMobile按鈕向下顏色
- 25. 改變按鈕顏色
- 26. NativeScript按鈕文本顏色
- 27. 設置按鈕顏色
- 28. 按鈕顏色不改變
- 29. 按鈕顏色-Windows Phone 7
- 30. 更改按鈕顏色
你有沒有這樣做實現呢?任何示例代碼都會非常有幫助。 – Abhinav 2010-11-22 17:47:08
查看我上面發佈的鏈接。 – 2010-11-22 17:50:23
非常感謝你! – Abhinav 2010-11-22 18:21:18