【问题标题】:Adding an icon or image on a UIPreviewAction在 UIPreviewAction 上添加图标或图像
【发布时间】:2017-11-07 12:51:19
【问题描述】:

我想知道是否有任何方法可以将图标添加到与 peek & pop 预览相关的快速操作(可通过 3D 触摸访问)。

我使用以下方法创建了几个预览操作:

UIPreviewAction(title: "Save".localized, style: .Default)

但我没能找到将任何类型的图标或图像添加到按钮以使其更易于理解的方法。

https://i.stack.imgur.com/qgtE5.png

示例:第二行有一个图标(经过照片处理) 如我所愿。

【问题讨论】:

    标签: ios arrays swift 3dtouch uipreviewaction


    【解决方案1】:

    您可以为您的操作添加尾随图标:

    extension UIPreviewAction {
    
    private var imageKey: String {
        return "image"
    }
    
    var actionImage: UIImage? {
        get {
            if self.responds(to: Selector(imageKey)) {
                return self.value(forKey: imageKey) as? UIImage
            }
            return nil
        }
        set {
            if self.responds(to: Selector(imageKey)) {
                self.setValue(newValue, forKey: imageKey)
            }
        }
    }
    }
    

    使用方法:

    yourAction.actionImage = UIImage(named: "somePicture")
    

    【讨论】:

      猜你喜欢
      • 2021-01-20
      • 1970-01-01
      • 1970-01-01
      • 2014-03-18
      • 1970-01-01
      • 2021-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多