Adding dismiss button for the GalleryVC
Closed this issue · 11 comments
I tried adding a dismiss button, but it did not show, is there any way to have a dismiss button in the zooming page?
Not at this point. I need to work on it.
Generally, the zooming screen does dismiss itself on a tap. That is the reason we did not put a dismiss button. Wouldn't the tap to dismiss good enough for what you are trying to do? If not, I could work on a solution to make it easier to be used, etc. I like new ideas anyways :)
Please, i would really a dismiss button. We have funny users in our Country here, am sure they will complain about something like this.
THank you very much, for this wonderful library.
Do you think could do it yourself? You can fork the project and then create a pull request when you are done. I can then review it and accept it or give you advice on how to make it better. You can practice writing code in that way? Do you like the idea?
Yes, I like the idea, actually, i tried adding the button myself, but it does not show, let me share my code.
var closeButton: UIButton = {
let button = UIButton()
button.setImage(#imageLiteral(resourceName: "close"), for: .normal)
return button
}()
fileprivate func setupUI() {
view.backgroundColor = .black
view.addSubview(closeButton)
closeButton.topAnchor.constraint(equalTo: view.topAnchor, constant: 20).isActive = true
closeButton.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 20).isActive = true
closeButton.widthAnchor.constraint(equalToConstant: 40).isActive = true
closeButton.heightAnchor.constraint(equalToConstant: 40).isActive = true
view.bringSubview(toFront: closeButton)
closeButton.addTarget(self, action: #selector(dismissView), for: .touchUpInside)
}
func dismissView() {
dismiss(animated: true, completion: nil)
}
Hey, there, what VC did you out the code into?
Hi, I did that in the GalleryVC, I also tried it in the GalleryItemVC, still the same issue.
Cause it should go in the GalleryItemVC, yes. Did you try making it work by using the storyboard?
Your code seems alright and all nice and i wonder why it doesn't work. I will give it a try and let you know what happens. Meanwhile, could you try doing the same using the storyboard?
OK, I will try with a storyboard.
I do see the issue with your code now. You need to give the button a size using CGRect, etc.
For example:
let button = UIButton(frame: CGRect(x: 100, y: 100, width: 100, height: 50))
Check out the link for a full description of how to do it:
https://stackoverflow.com/questions/24030348/how-to-create-a-button-programmatically
Afterwards, you can add the constraints programmatically and it should work fine.
It is quite a simple operation though and I would recommend using storyboards for that.
Thanks, I got it working, the issue was with the image, I had the drag the image to the Resource of SwiftImageCarousel
.
Yeah, that seems another plausible reason? Do you want to create a pull request? It would be nice to have it as a feature in the library for other people to use as well.