Closed nicholas-jomo closed 7 years ago
Thanks! Looks like you added many handy features. I'll take a more in-depth look at your pull request in the next days.
I just took a look at your pull request. The changes in DropDownMenu and DropDownMenuCell looks good.
For DropDownTitleView, to support customizing the up/down images, I'd suggest to simply declare iconSize as an instance variable rather than a static one, and change setUp() into an open method:
open var iconSize = CGSize(width: 12, height: 12)
open func setUp() { // some code }
This also means replacing any access to DropDownTitleView.iconSize with self.iconSize.
Then it's possible to customize the images or image views with a subclass like this:
open class CustomDropDownTitleView : DropDownTitleView {
open override func setUp() {
iconSize = CGSize(width: 8, height: 8)
menuDownImageView.image = UIImage(named: "Ionicons-ios-checkmark-outline")
menuDownImageView.transform = CGAffineTransform.identity
menuUpImageView.image = UIImage(named: "Ionicons-ios-search")
super.setUp()
}
}
You could also customize properties like iconSize or menuDown/UpImageView from the outside without creating a dedicated subclass.
Let me know if this approach would work for you.
Thanks for your suggestion!
I'm not sure if my approach is the best, my thoughts are:
init
... i can't really change it after it's added to the view. Hence I added a config DropDownTitleConfig
to properly declare the up/down images and then new images would be added to view during init
iconSize
, as I updated the code here, so it actually would use the actual image size to define the imageView
frame, and wouldn't follow DropdownTitleView.iconSize
..... maybe I could remove the iconSize
property as well?? As iconSize
seems redundant, once imageView
follow the actual image size.Thoughts are appreciated.
For iconSize
, I want to keep it, since it makes it easy to scale images or use images with mismatched sizes. If you want a more precise control on the image view positions and sizes, you can override layoutSubviews().
To get the image views properly resized when setting their images, the best would be to trigger a new layout update when setting the icon size and recompute the image view sizes in layoutSubviews().
For the API, I want to avoid introducing a new class, struct or methods like DropDownTitleConfig. The behavior you're looking for can be supported by tweaking the implementation I think.
Here is a revised version of the code I gave in my previous comment. The following should be extracted out of menuDown/UpImageView initialization code and put into layoutSubviews():
menuDownImageView.frame.size = iconSize
menuUpImageView.frame.size = iconSize
imageView.frame.size = iconSize
The property iconSize should be changed to:
open var iconSize = CGSize(width: 12, height: 12) {
didSet {
setNeedsLayout()
}
}
With these changes, you can now easily update the images without even overriding setUp(). For instance, the following can be put in ViewController.select() of the app example:
titleView.iconSize = CGSize(width: 24, height: 24)
titleView.menuDownImageView.image = UIImage(named: "Ionicons-ios-checkmark-outline")
titleView.menuDownImageView.transform = CGAffineTransform.identity
titleView.menuUpImageView.image = UIImage(named: "Ionicons-ios-search")
thanks again. I tried your approach and it all worked out. Added example codes too
I had completely forgot to merge this pull request, sorry.
The changes are now merged into master. I fixed issues related to indentation and height support.
Thanks a lot for your contribution.
This library is great, I've added a few configuration so it can fit into more design.
cheers.