ios – 向UIActivityViewController添加一个明显的(自定义)按钮

ios – 向UIActivityViewController添加一个明显的(自定义)按钮,第1张

概述我只想添加明显的按钮“在Safari中打开” 我怎么能以简单的方式做到这一点. #pragma mark - Share the link- (IBAction)activityButtonPressed:(id)sender { NSString *textToShare = @"I just shared this from my App"; // UIImage *ima 我只想添加明显的按钮“在Safari中打开”
我怎么能以简单的方式做到这一点.
#pragma mark - Share the link- (IBAction)activitybuttonpressed:(ID)sender {    Nsstring *textToShare = @"I just shared this from my App";   // UIImage *imagetoShare = [UIImage imagenamed:@"Image.png"];    NSURL *urlToShare = [NSURL URLWithString:@"http://www.Google.com"];    NSArray *activityItems = [NSArray arrayWithObjects:textToShare,urlToShare,nil];    UIActivityVIEwController *activityVC = [[UIActivityVIEwController alloc]initWithActivityItems:activityItems applicationActivitIEs:Nil];    //This is an array of excluded activitIEs to appear on the UIActivityVIEwController    //activityVC.excludedActivityTypes = @[UIActivityTypeMessage,UIActivityTypecopytopasteboard,UIActivityTypeSavetoCameraRoll];    [self presentVIEwController:activityVC animated:TRUE completion:nil];}
解决方法 因为nevo shalev说你需要子类 UIActivity class

这是一个例子:

UrlActivity.h

#import <UIKit/UIKit.h>@interface UrlActivity : UIActivity@end

UrlActivity.m:

#import "UrlActivity.h"@implementation UrlActivity- (Nsstring *)activityType{    return @"your Custom Type";}- (Nsstring *)activityTitle{    return @"Title to display under your icon";}- (UIImage *)activityImage{    return [UIImage imagenamed:@"your icon.png"];}- (BOol)canPerformWithActivityItems:(NSArray *)activityItems{    // basically in your case: return YES if activity items are urls  }- (voID)prepareWithActivityItems:(NSArray *)activityItems{    //open safari with urls (activityItems)}+(UIActivitycategory)activitycategory{    return UIActivitycategoryShare; // says that your icon will belong in application group,not in the lower part;}@end

并在您的主文件(导入UrlActivity.h后):

#pragma mark - Share the link- (IBAction)activitybuttonpressed:(ID)sender {    Nsstring *textToShare = @"I just shared this from my App";   // UIImage *imagetoShare = [UIImage imagenamed:@"Image.png"];    NSURL *urlToShare = [NSURL URLWithString:@"http://www.Google.com"];    NSArray *activityItems = [NSArray arrayWithObjects:textToShare,nil];    // create an array with your custom activity and add it to the activityVC    NSArray *appActivitIEs = [NSArray arrayWithObjects:[[UrlActivity alloc] init]]];    UIActivityVIEwController *activityVC = [[UIActivityVIEwController alloc]initWithActivityItems:activityItems applicationActivitIEs:appActivitIEs];    //This is an array of excluded activitIEs to appear on the UIActivityVIEwController    //activityVC.excludedActivityTypes = @[UIActivityTypeMessage,UIActivityTypeSavetoCameraRoll];    [self presentVIEwController:activityVC animated:TRUE completion:nil];}
总结

以上是内存溢出为你收集整理的ios – 向UIActivityViewController添加一个明显的(自定义)按钮全部内容,希望文章能够帮你解决ios – 向UIActivityViewController添加一个明显的(自定义)按钮所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1095684.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存