UIActionSheet button's color

后端 未结 5 991
失恋的感觉
失恋的感觉 2020-11-29 06:27

How can I change the color of UIActionSheet button\'s color?

5条回答
  •  情话喂你
    2020-11-29 06:47

    We can use background images to do it. I think it is the easiest way.

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

提交回复
热议问题