0

I want to create action sheet with two buttons, but i want the buttons to have thumbnail icons, is that possible? any other solutions? maybe there is a way to customize the action sheet buttons.. like to design them separately?

this is my current action sheet method:

- (void)tapResponder {

    NSLog(@"Tap!");

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"this is a title"
                                                             delegate:self
                                                    cancelButtonTitle:@"Cancel"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:@"one", @"two", nil];
    [actionSheet showInView:self.view];
}

but i really like to stay with ios design so please give me a cool solution :))

thankssss!

nick shmick
  • 905
  • 1
  • 9
  • 25

2 Answers2

0

Maybe this helps:

for (UIView *subview in actionSheet.subviews) {
    if( [subview isKindOfClass: [UIButton class]] ){
        UIButton* btn = (UIButton*) subview;
        [btn setImage:[UIImage imageNamed: @"imageName"] forState:UIControlStateNormal];
    } 
}
3CC
  • 502
  • 3
  • 11
0

Very possible, very easy to implement :

This works with the new UIAlertController as well :

UIAlertController *alertC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerSytleActionSheet];

//Add your Actions
...
UIAlertAction *snapshot = [UIAlertAction actionWithTitle:@"Snapshot" style:UIAlertActionSytleDefault handler:^(UIAlertAction *action) {
}
//create a UIImage to display since it's technically a tableView:
UIImage *snapshotImage = [UIImage imageNamed:@"snapshot.png"];
//add it to the UIAlertAction of your choosing 
[snapshot setValue:snapshotImage forKey:@"image"];
...
[alertC addAction:snapshot];
[self presentViewController:alertC animated:YES completion:nil];

Prior to iOS 8 it can be done this way:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"this is a title"
                                                         delegate:self
                                                cancelButtonTitle:@"Cancel"
                                           destructiveButtonTitle:nil
                                                otherButtonTitles:@"one", @"two", nil];

[[[action valueForKey:@"_buttons"] objectAtIndex:0] setImage:[UIImage imageNamed:@"yourImage.png"] forState:UIControlStateNormal];

[[[action valueForKey:@"_buttons"] objectAtIndex:0] setImage:[UIImage imageNamed:@"yourImage_Highlighted.png"] forState:UIControlStateHighlighted];

[actionSheet showInView:self.view];

A couple of notes about this, make sure you properly size your image, whatever the H x W demensions are is how huge the row will become once it's inserted into the Action Sheet. So use something like 30x30. Also, whatever color your image is will default to the blue tint. Additionally, this isn't considered public API, apps do get approved this way, but you do run the risk

soulshined
  • 9,612
  • 5
  • 44
  • 79
  • thanks buddy, I dont really get your example here bro, I tried it and it and I had some issues. Just edited my question to show how my action shoot works, could you please change your example according to my code maybe then I will get it? thanks a bunch :) – nick shmick Feb 01 '15 at 22:00
  • UIActionSheet is deprecated @nickshmick Are you coding strictly for iOS8? – soulshined Feb 01 '15 at 22:08
  • @nickshmick see my revised answer if your not coding for >= iOS8 – soulshined Feb 01 '15 at 23:11