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

Icons in KCFloatingActionButtonItem distorted #44

Closed
tylerjames opened this issue Jul 8, 2016 · 1 comment
Closed

Icons in KCFloatingActionButtonItem distorted #44

tylerjames opened this issue Jul 8, 2016 · 1 comment

Comments

@tylerjames
Copy link

tylerjames commented Jul 8, 2016

Hey, I noticed that some of my icons seemed a bit squished. I checked in the code and found this:

/**
 Item's icon image view.
 */
var _iconImageView: UIImageView? = nil
public var iconImageView: UIImageView {
    get {
        if _iconImageView == nil {
            _iconImageView = UIImageView(frame: CGRectMake(0, 0, 21, 23))
            //                _iconImageView = UIImageView(frame: CGRectMake(frame.size.width - size, 0, 21, 23))
            _iconImageView?.center = CGPointMake(size/2, size/2) + imageOffset
            _iconImageView?.contentMode = UIViewContentMode.ScaleToFill
            addSubview(_iconImageView!)
        }
        return _iconImageView!
    }
}

In this line:
_iconImageView = UIImageView(frame: CGRectMake(0, 0, 21, 23))
you can see that the image view is not a square.

And in this line:
_iconImageView?.contentMode = UIViewContentMode.ScaleToFill
... the content mode is set to .ScaleToFill which does not maintain the image aspect ratio.

Solution
If you set it to .ScaleAspectFill it will maintain the ratio and not distort the images.

@kciter
Copy link
Owner

kciter commented Jul 12, 2016

I fixed it.
From:

_iconImageView = UIImageView(frame: CGRectMake(0, 0, 21, 23))
_iconImageView?.contentMode = UIViewContentMode.ScaleToFill

To:

_iconImageView = UIImageView(frame: CGRectMake(0, 0, 25, 25))
_iconImageView?.contentMode = UIViewContentMode.ScaleAspectFill

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants