alexhillc / AXPhotoViewer

An iOS/tvOS photo gallery viewer, useful for viewing a large (or small!) number of photos.
https://www.cocoacontrols.com/controls/axphotoviewer
MIT License
646 stars 119 forks source link

How to hide the share icon in the photo viewer? #32

Closed chrisvoronin closed 5 years ago

chrisvoronin commented 6 years ago

Hi Alex,

Just let me say this first... very awesome library, saved me a ton of time. Thank you for making this and sharing this. Using Kingfisher loader too.

One quick question I have, is there an easy way to hide the share icon? I didn't see some option when I looked around.

Thank you,

Chris

alexhillc commented 6 years ago

Hey @chrisvoronin, this should be possible by setting: PhotosViewController.overlayView.rightBarButtonItem = nil

bizibizi commented 6 years ago

@alexhillc is there any way to replace the icon?

      photosViewController.overlayView.leftBarButtonItem?.image = UIImage(named: "close-icon")

does not work (version 1.2.10)

bizibizi commented 6 years ago

And I need to remove Share as well, but this code does not work šŸ˜­@alexhillc

alexhillc commented 6 years ago

Hey @bizibizi, in earlier versions of AXPhotoViewer (1.2.10) the overlay was instantiated with the rest of the views, which made it inconvenient to customize it before presenting the view controller. To get around this, simply load the view before customizing the pager:

photosViewController.loadViewIfNeeded()
photosViewController.overlayView.rightBarButtonItem = nil

As for the close button, you will have to subclass the PhotosViewController and override closeBarButtonItem, returning a UIBarButtonItem with a custom image. You can leave the target and action of the UIBarButtonItem nil (the pager will set these manually). That should get the behavior that you are expecting.

However, I do recommend updating your project to Swift 4! With the Swift 4 update came many key iOS 11 features, including safe area insets.

bizibizi commented 6 years ago

Yes, this works, thank you! And how can I add share button to the bottom (with custom image preferable). I am looking on the code sample but looks like 1.2.10 does not have ā€œbottomStackContainerā€ to do that:

 photosViewController.overlayView.bottomStackContainer.insertSubview(bottomView, at: 0)

And how can I attach ā€œtarget and actionā€ to that share button?

On May 10, 2018, at 18:43, Alex Hill notifications@github.com wrote:

Hey @bizibizi https://github.com/bizibizi, in earlier versions of AXPhotoViewer (1.2.10) the overlay was instantiated with the rest of the views, which made it inconvenient to customize it before presenting the view controller. To get around this, simply load the view before customizing the pager:

photosViewController.loadViewIfNeeded() photosViewController.overlayView.rightBarButtonItem = nil As for the close button, you will have to subclass the PhotosViewController and override closeBarButtonItem, returning a UIBarButtonItem with a custom image. You can leave the target and action of the UIBarButtonItem nil (the pager will set these manually). That should get the behavior that you are expecting.

However, I do recommend updating your project to Swift 4! With the Swift 4 update came many key iOS 11 features, including safe area insets.

ā€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/alexhillc/AXPhotoViewer/issues/32#issuecomment-388111488, or mute the thread https://github.com/notifications/unsubscribe-auth/AF2Tip1MkWjJsnZ-65_lW4biXR5o-JNpks5txG4wgaJpZM4T5K58.

alexhillc commented 6 years ago

@bizibizi, unfortunately in older versions of the library there is not a viable way to do what you want. As you said, in 1.2.10, there is no "bottomStackContainer", so adding custom views to the bottom of the photo viewer becomes a pain.

I guess what you could do is create an AXCaptionView subclass (caption view lives at the bottom of the photo viewer, so that should get you what you want) and include a share button in that view. You can set a custom caption view using the following:

photosViewController.loadViewIfNeeded()
photosViewController.overlayView.captionView = SomeCustomCaptionView()