My app support iOS 7+, I use UIActivity image size: 60pt for iPhone, 76pt for iOS for iPad,
When touch more button to re-order the items, it can't show the icon in the list.
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
}
}
}
Quite old question, but maybe the solution is helpful for others too!
In your UIActivity subclass implement/overwrite the method
- (UIImage *)activityImage {
return [UIImage imageNamed:@"Activity Icon"];
}
to return the image to be shown in the UIActivityViewController itself (as you've done).
In addition to this implement/overwrite the method
- (UIImage *)activitySettingsImage {
return [UIImage imageNamed:@"Activity Settings Icon"];
}
to return an(other or the same) image to be shown in the more/settings view.
I haven't found the second method in the docs, but it is none of the '_xx' method of UIAction, so I would guess it isn't private...
UIActivity
has an undocumented activitySettingsImage
property. The following code shows how to implement it with Swift 3 in order to display a thumbnail of your custom activity in the "Activities" 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
}
/* ... */
}
Note that you don't have not override activitySettingsImage
to implement it in your code.
I found the solution in Swift.
@objc var _activitySettingsImage: UIImage? {
return UIImage(named: "icon")!
}
The image is 29x29 + @2x + @3x. Rather activityImage, no mask is apply to the image. If you want rounded corners, you must add them.
Works with Swift 5 on iOS 12
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With