UIActivity user share, the thumbnail icon does not appear when you click the more button

My support for iOS 7+ applications, I use UIActivity image size: 60pt for iPhone, 76pt for iOS for iPad,

When you click the more button to reorder items, it cannot display the icon in the list.

Show share activities

enter image description here

CODE as below:

class ZYShare { class ActivityItem { init() { self.title = "" self.icon = "" } var title: String? var icon: String? var type: ShareType = ShareTypeAny } class CommonActivity: UIActivity { lazy var itemInfo = ActivityItem() override func prepareWithActivityItems(activityItems: [AnyObject]) { // do something } override func canPerformWithActivityItems(activityItems: [AnyObject]) -> Bool { return true } override class func activityCategory() -> UIActivityCategory { return UIActivityCategory.Action } override func activityType() -> String? { return NSLocalizedString(itemInfo.title ?? "", comment: "") } override func activityTitle() -> String? { return NSLocalizedString(itemInfo.title ?? "", comment: "") } override func activityImage() -> UIImage? { println(itemInfo.icon) if let icon = itemInfo.icon { return UIImage(named: icon) } else { return nil } } override func performActivity() { ShareSDK.showShareViewWithType(itemInfo.type , container: nil , content: publishContent , statusBarTips: false , authOptions: authOptions , shareOptions: options , result: handle) self.activityDidFinish(true) } } class QQActivity: CommonActivity { override init() { super.init() self.itemInfo.icon = "ShareToQQ" self.itemInfo.title = "QQ" self.itemInfo.type = ShareTypeQQ } } class WeChatSessionActivity: CommonActivity { override init() { super.init() self.itemInfo.icon = "ShareToWeChat" self.itemInfo.title = "微信" self.itemInfo.type = ShareTypeWeixiSession } } class WeChatTimelineActivity: CommonActivity { override init() { super.init() self.itemInfo.icon = "ShareToWeChatTimeLine" self.itemInfo.title = "朋友圈" self.itemInfo.type = ShareTypeWeixiTimeline } } class QQSpaceActivity: CommonActivity { override init() { super.init() self.itemInfo.icon = "ShareToQzone" self.itemInfo.title = "QQ空间" self.itemInfo.type = ShareTypeQQSpace } } } 
+7
ios iphone share uiactivity
source share
2 answers

Pretty old question, but maybe the solution is useful for others too!

In a subclass, UIActivity implements / overwrites a method

 - (UIImage *)activityImage { return [UIImage imageNamed:@"Activity Icon"]; } 

to return the image that will be displayed in the UIActivityViewController itself (as you did).

In addition to this, the implementation / overwrites the method

 - (UIImage *)activitySettingsImage { return [UIImage imageNamed:@"Activity Settings Icon"]; } 

to return an image (different or the same) that will be displayed in the larger / settings view.

I did not find the second method in the docs, but this is not the "_xx" method for UIAction, so I would suggest that it is not private ...

+4
source share

UIActivity has an undocumented property activitySettingsImage . The following code shows how to implement it using Swift 3 to display a thumbnail of your user activity in the Actions list:

 import UIKit class MyActivity: UIActivity { override var activityType: UIActivityType? { return UIActivityType(rawValue: String(describing: classForCoder)) } override var activityTitle: String? { return "My Activity Title" } override var activityImage: UIImage? { return UIImage(named: "icon") } var activitySettingsImage: UIImage? { return UIImage(named: "icon") } override class var activityCategory: UIActivityCategory { return .share } /* ... */ } 

Please note that you are not overriding activitySettingsImage to implement it in your code.

+1
source share

All Articles