alexisakers / BulletinBoard

General-purpose contextual cards for iOS
MIT License
5.38k stars 305 forks source link

Accessing the BLTNPageItem ImageView #86

Open sejr opened 6 years ago

sejr commented 6 years ago

New Issue Checklist

Issue Description

I would like to set an image dynamically with Kingfisher, but it appears that the imageView is read-only (and apparently set to nil). Is it possible to do this without subclassing BLTNItem?

Environment

Example

This is an example subclass that I could not get to work.

class FriendRequestBulletin: BLTNPageItem {
    var fromUserImageContainer = UIView()
    var fromUserImageView = UIImageView()

    func setFromUserImage(withURL url: URL) {
        fromUserImageView.kf.setImage(with: url)
    }

    override func makeViewsUnderTitle(with interfaceBuilder: BLTNInterfaceBuilder) -> [UIView]? {
        fromUserImageView = UIImageView(frame: CGRect(x: 50, y: 0, width: 200, height: 200))
        fromUserImageView.layer.cornerRadius = 100
        fromUserImageView.contentMode = .scaleAspectFill
        fromUserImageView.clipsToBounds = true
        fromUserImageContainer.addSubview(fromUserImageView)
        fromUserImageContainer.heightAnchor.constraint(equalToConstant: 200.0).isActive = true
        return [fromUserImageContainer]
    }
}

Instantiating and displaying the above class:

let example: URL = URL(string: " . . . ")!
let exampleBulletin = FriendRequestBulletin(title: "Friend Request")

// Prep bulletin
exampleBulletin.isDismissable = false
exampleBulletin.descriptionText = "USER NAME wants to be your friend."
exampleBulletin.actionButtonTitle = "Accept"
exampleBulletin.alternativeButtonTitle = "Ignore"
exampleBulletin.setFromUserImage(withURL: example)

// Show bulletin
let manager: BLTNItemManager = BLTNItemManager(rootItem: exampleBulletin)
manager.showBulletin(above: self)
sejr commented 6 years ago

This is related to a point made in #82.

ajaxgoogle commented 3 years ago

How can I add gesture to ImageView?

If I try like this nothing happens, however if I call UIImageView extension method inside alternativeHandler it works well.

//inside bulletin 
item.imageView?.isUserInteractionEnabled=true
let tap = UITapGestureRecognizer(target: self, action: Selector("tapTap:"))
item.imageView?.addGestureRecognizer(tap)
//down in ViewController
@objc func tapTap(gestureRecognizer: UITapGestureRecognizer) {
    print("TAPTAP!!!!!!")
}