Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image size property to action items #203

Closed
ductranit opened this issue May 23, 2019 · 7 comments · Fixed by #213
Closed

Add image size property to action items #203

ductranit opened this issue May 23, 2019 · 7 comments · Fixed by #213
Milestone

Comments

@ductranit
Copy link

Hi, I wonder whether it can have a way to resize the menu icon in the button items? My action button & action items are quite large (130x130), but the icon size can't be changed although I use the large image. The icons look very small in the ipad.
Is there any way to do increaze their size by code? Some like:

actionButton.configureDefaultItem { item in
            item.size = CGSize()
@jjochen
Copy link
Owner

jjochen commented May 23, 2019

Hey, currently you can set itemSizeRatio on the action button to define the size of the items (see here)

If I remember correctly the image sizes are determined by its original size. If this doesn't work, something is wrong.

Could you post the image you are using, the size of the action button and the value of itemSizeRatio you are using? Then I could check what's happening.

@ductranit
Copy link
Author

@jjochen My code is

actionButton.itemSizeRatio = 0.95
actionButton.widthAnchor.constraint(equalToConstant: 130).isActive = true
actionButton.heightAnchor.constraint(equalToConstant: 130).isActive = true

My image is the pdf vector, it's small by default, but I though it could scale up?
menu-profiles.pdf
The item size can be changed according the action button, but not the icon https://gyazo.com/1c11cfab03b464a1aafb8caa571f4d75

@jjochen
Copy link
Owner

jjochen commented May 23, 2019

Yes, that's it. I think the intrinsic content size of the image view is used which uses the original size of the image.
Also the pdf appears to contain a lot of whitespace around the actual icon. Maybe removing that is already enough?

On the other hand it's probably a good idea to be able to fix the image size somehow independent of the actual image size.

@jjochen
Copy link
Owner

jjochen commented May 23, 2019

For now you could use something like this:

actionButton.configureDefaultItem { item in
            let imageSizeMuliplier = CGFloat(1 / sqrt(2));
            item.imageView.widthAnchor.constraint(equalTo: item.circleView.widthAnchor, multiplier: imageSizeMuliplier).isActive = true
            item.imageView.heightAnchor.constraint(equalTo: item.circleView.heightAnchor, multiplier: imageSizeMuliplier).isActive = true
        }

The multiplier can't be greater than that because the constraints have to work with the existing ones here. Otherwise you would have to remove the existing constraints first.

@ductranit
Copy link
Author

ductranit commented May 23, 2019

@jjochen Thanks for you help. But how can I remove the existing constraints? The constraints code is in the library.
I try something like this:

actionButton.configureDefaultItem { item in
            //let imageSizeMuliplier = CGFloat(1 / sqrt(2)) // it looks small with this muliplier
            NSLayoutConstraint.deactivate(item.imageView.constraints)
            item.imageView.widthAnchor.constraint(equalTo: item.circleView.widthAnchor, multiplier: 0.9).isActive = true
            item.imageView.heightAnchor.constraint(equalTo: item.circleView.heightAnchor, multiplier: 0.9).isActive = true
        }

And the action items are disappeared cause it conflicts with the existing ones as you said

@ductranit
Copy link
Author

Btw, I remove the whitespace around the actual icon, then scale up image and it works. Hope you can add a feature to resize later. Thanks

@jjochen
Copy link
Owner

jjochen commented May 24, 2019

@ductranit That's good to hear! I think that's actually the best way to go.

I might add an image size property once I have a bit more time at hand.

@jjochen jjochen changed the title How to resize the image for action item? Add image size property to action items May 24, 2019
@jjochen jjochen removed the support label May 24, 2019
@jjochen jjochen added this to the 2.1.0 milestone Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants