如何更改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