【问题标题】:Custom UIActivityViewController not appear image when it is in the "More" menu item自定义 UIActivityViewController 在“更多”菜单项中时不会出现图像
【发布时间】:2020-04-04 15:19:16
【问题描述】:

我创建了自定义 UIActivity 并使用我的图像覆盖了变量 activityImage。

fileprivate extension UIActivity.ActivityType {
   static let extendedMessage = 
UIActivity.ActivityType("ExtendedMessage")
}

自定义 UIActivity:

fileprivate class ExtendedMessageActivity: UIActivity {

private let phoneNumbers: [String]
private var message: String?
init(phoneNumbers: [String]) {
    self.phoneNumbers = phoneNumbers
    super.init()
}

override static var activityCategory: UIActivity.Category {
    return .share
}
override var activityType: UIActivity.ActivityType? { return .extendedMessage }

override var activityTitle: String? { return NSLocalizedString("Message", comment: "") }

override var activityImage: UIImage? {
    return UIImage(named: "message-app-icon")
}

override func canPerform(withActivityItems activityItems: [Any]) -> Bool {
    ....
}
override func prepare(withActivityItems activityItems: [Any]) {
  ....
}

override func perform() {
    ....
}

}

The image appears in the set. I have a problem the image does not appear when it is in the "More" menu item. 为什么图片没有出现?

【问题讨论】:

    标签: ios


    【解决方案1】:

    曾尝试查找活动设置图标的文档。没有找到合适的文档。只需在您的自定义 UIActivity 中添加以下代码,使用 Swift 5.2 对我来说工作得很好

    @objc var _activitySettingsImage: UIImage? {
        return UIImage(named: "activitySettingsIcon")
    }
    

    不要忘记将activitySettingsIcon图像设置在29pt。

    【讨论】:

      【解决方案2】:

      我通过添加以下内容解决了同样的问题(在 Objective C 中,但你明白了)。

      - (UIImage *)_activitySettingsImage {
              return [UIImage imageNamed:@"message-app-icon-for-setting"];
      }
      

      显然,更多部分的图像应该小于 _activityImage 中的图像。在撰写本文时(XCode 12.3),activityImage 的 60pt 和 activitySettingsImage 的 30pt 对我有用。 (我还为每张图片添加了@2x)..

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-03
        • 1970-01-01
        相关资源
        最近更新 更多