如何在iOS中创建自定义UIActivity?如何UIActivity在iOS中创建自定义?我想要这个的原因是在我的一个应用程序中添加一个Review App按钮,将用户带到App Store的评论部分。我该如何创建这样的自定义UIActivity?
3 回答
浮云间
TA贡献1829条经验 获得超4个赞
我的Swift 3实现基于DogCoffee的:
class ActivityViewCustomActivity: UIActivity { // MARK: Properties var customActivityType: UIActivityType var activityName: String var activityImageName: String var customActionWhenTapped: () -> Void // MARK: Initializer init(title: String, imageName: String, performAction: @escaping () -> Void) { self.activityName = title self.activityImageName = imageName self.customActivityType = UIActivityType(rawValue: "Action \(title)") self.customActionWhenTapped = performAction super.init() } // MARK: Overrides override var activityType: UIActivityType? { return customActivityType } override var activityTitle: String? { return activityName } override class var activityCategory: UIActivityCategory { return .share } override var activityImage: UIImage? { return UIImage(named: activityImageName) } override func canPerform(withActivityItems activityItems: [Any]) -> Bool { return true } override func prepare(withActivityItems activityItems: [Any]) { // Nothing to prepare } override func perform() { customActionWhenTapped() }}
- 3 回答
- 0 关注
- 967 浏览
添加回答
举报
0/150
提交
取消