如何在iOS中的UIActionSheet中设置imageview

时间:2015-09-04 13:31:52

标签: ios objective-c uiactionsheet

在我的应用程序中有共享选项,所以我想在Actionsheet中打开该共享选项。 如何实现这一功能?

NSArray * itemsArray = @[@"www.google.com", @"Google", @"5.png"]; // Anything you want to share
NSArray * applicationActivities = nil;

UIActivityViewController * activityViewController = [[UIActivityViewController alloc] initWithActivityItems:itemsArray applicationActivities:applicationActivities];

if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0"))
{
     activityViewController.popoverPresentationController.sourceView = self.view;
}
[self presentViewController:activityViewController animated:YES completion:nil];

我想分配自己的自定义图片,链接和文字,以便如何实现这个

enter image description here

1 个答案:

答案 0 :(得分:1)

为什么不使用UIActivityViewController?因此系统可以处理分享位置:

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)


UIImage * image = [UIImage imageNamed:@"yourimage.png"];
NSArray * itemsArray = @[image]; // Anything you want to share


    NSArray * applicationActivities = nil;

    UIActivityViewController * activityViewController = [[UIActivityViewController alloc] initWithActivityItems:itemsArray applicationActivities:applicationActivities];

    activityViewController.excludedActivityTypes = @[
                                                     UIActivityTypePostToWeibo,
                                                     UIActivityTypeAssignToContact,
                                                     UIActivityTypeAirDrop,
                                                     UIActivityTypeAddToReadingList
                                                     // Whatever you want to exclude
                                                     ];

    if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")){
        activityViewController.popoverPresentationController.sourceView = self.view;
    }

    [self presentViewController:activityViewController animated:YES completion:nil];