Adding Images to UIActionSheet buttons as in UIDocumentInteractionController

后端 未结 12 1616
我寻月下人不归
我寻月下人不归 2020-11-30 19:39

Is it possible to add an image to the buttons of the UIActionSheet as seen in UIDocumentInteractionController? If so, please let me know how it is

12条回答
  •  青春惊慌失措
    2020-11-30 19:53

    I just created a class emulating the look of an UIActionSheet using table cells supporting images and text for every row. It also uses blocks for interaction, supports iPhone and iPad, popup from an UITabBarItem on iPad and queueing of multiple sheets. Still in development, but feel free to clone it from Github:

    http://github.com/azplanlos/SIActionSheet

    Usage is quite simple, here is an example:

    SIActionSheet* mySheet = [SIActionSheet actionSheetWithTitle:@"Action Sheet title"
        andObjects:[NSArray arrayWithObjects:
            [SIActionElement actionWithTitle:@"Item 1"
                image:[UIImage imageNamed:@"image"]
                andAction:^{NSLog(@"action 1");}]
        , nil]
        completition:^(int num) {
            NSLog(@"pressed %i", num);
        } cancel:^{NSLog(@"canceled");}];
    
    mySheet.followUpSheet = anotherSheet;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
            [mySheet show];
    else
            [mySheet showFromTabBarItem:item inTabBar:tabBar];
    

    If you encounter any problems, please let me know. I hope this helps a lot of people having the same problem like me...

提交回复
热议问题