更改UIActionSheet按钮颜色

来源:互联网 发布:数据有效性 日期 编辑:程序博客网 时间:2024/05/24 06:01

使用如下方法定义UIActionSheet,其中颜色按钮的颜色为红色。

UIActionSheet *ActionSheet = [[UIActionSheet alloc] initWithTitle:@" " 

                                                                     delegate:self 
                                                            cancelButtonTitle:@"删除" 
                                                       destructiveButtonTitle:@"颜色" 
                                                            otherButtonTitles:@"Done",nil];

            [ActionSheet setActionSheetStyle:UIActionSheetStyleDefault];


1、修改颜色按钮的颜色为默认的蓝色的方法

UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@""   delegate:self 
  cancelButtonTitle:nil 
  destructiveButtonTitle:nil 
  otherButtonTitles:nil]; 
[sheet addButtonWithTitle:@"颜色"]; 
[sheet addButtonWithTitle:@"删除"]; 

sheet.cancelButtonIndex = sheet.numberOfButtons-1; 


2、修改按钮的颜色为其他颜色的方法

实现代理方法

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet

{

   for (UIView *subViwein actionSheet.subviews) {

       if ([subViwe isKindOfClass:[UIButtonclass]]) {

           UIButton *button = (UIButton*)subViwe;

            [buttonsetTitleColor:[UIColorblueColor]

                        forState:UIControlStateNormal];

        }

    }

}




0 1
原创粉丝点击