1and2papa / CTAssetsPickerController

iOS control that allows picking multiple photos and videos from user's photo library.
MIT License
2.15k stars 550 forks source link

[Question] How to customize specific UIBarButton? #179

Closed d9j closed 8 years ago

d9j commented 8 years ago

Thank you for a helpful library.

I've spent a whole day figuring out how I can customize a specific UIBarButton. The code in the demo app https://github.com/chiunam/CTAssetsPickerController/blob/master/CTAssetsPickerDemo/Examples/CTApperanceViewController.m#L84 doesn't give a clear example of how it can be done I want to change title of a button "Done" to "Upload" ., and also I would like to change the design of buttons. Currently it displays On the left is shown current button design . and desired on the right.

4-ui-issue2

I've just looking into a source code. there is no way to access ui items UIBarButtonItem * cancelButton , UIBarButtonItem * doneButton in CTAssetCollectionViewController

Therefore I presume they can't be customized individually. moreover class CTAssetCollectionViewController cannot be extended

Thank you!

1and2papa commented 8 years ago

Hi @LinkedHK, really nice to know someone from Hong Kong!

Re the first question, you can override "Done" button title by assigning doneButtonTitle property in v3.2.0 or above.

Re the second one, I believe you have another global UIAppearance set so all styles of UIBarButton are overridden. You could set the style by using appearanceWhenContainedIn: appearance proxy and pass [CTAssetsPickerController class] as parameter. Please refer to the documentation of UIAppearance.

d9j commented 8 years ago

Hi., @chiunam I appreciate your for help. However. It only solved part of problem. According to design requirements (see at the right screenshot above) The "done" button should be displayed only inside of the album or if user picks some images it may also be displayed outside of album. Since there is is no public method available to detect if user is inside an album I had to look into the source code of your library; the class CTAssetCollectionViewController has the method isTopViewController which suits my need . In order to solve my problem I created a subclass of classes CTAssetCollectionViewController and CTAssetsPickerController.. and achieved my goal using reflection. So Basically I hacked your Library :) Thanks again for the help!