0

How do I add an image in the circled part of the UIActivityController? I don't need it included in the sharing part, I want to add it right there. I tried:

ac.tabBarItem.image = UIImage(named: "uLogo")

let items:[Any] = [UIImage(named: "uLogo"), "What do you think of my Take on the uSTADIUM App? Sign up so you can bet with or against me!", url]
let ac = UIActivityViewController(activityItems: items, applicationActivities: [])

Which doesn't work, so not sure how to do this

enter image description here

tHatpart
  • 1,302
  • 3
  • 12
  • 27

1 Answers1

1

you can try custom UIActivityViewController

class ActivityCtrl: UIActivityViewController{
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        if let cls = NSClassFromString("LPImageView"), let base = getBase(for: view, cls){
            for sub in base.subviews{
                if let img = sub as? UIImageView{
                    img.image = UIImage(named: "uLogo.png")
                    break
                }
            }
        }
    }
    
    
    
    func getBase(for v: UIView?, _ cls: AnyClass) -> UIView?{
           guard let vue = v else{ return nil }
           var result: UIView?
           for sub in vue.subviews{
               if sub.isKind(of: cls){
                   return sub
               }
               else {
                   result = getBase(for: sub, cls)
                   if result != nil{
                       return result
                   }
               }
           }
           return result
       }
}

usage:

if let url = URL(string: "https://www.baidu.com"), let img = UIImage(named: "uLogo"){
            let items:[Any] = [img, "What do you think of my Take on the uSTADIUM App? Sign up so you can bet with or against me!", url]
            let ac = ActivityCtrl(activityItems: items, applicationActivities: [])
            present(ac, animated: true){ }
        }

The result:

999


How I know LPImageView?

888

black_pearl
  • 2,549
  • 1
  • 23
  • 36