如何更改UIActionSheet中文本按钮的颜色?

时间:2014-09-12 07:25:25

标签: ios objective-c xcode

在UIActionSheet按钮的文字颜色为蓝色。如何设置为红色或绿色或黑色?

1 个答案:

答案 0 :(得分:1)

使用这种简单的方法更改文本颜色。

- (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];
      }
  }
}