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

How i can get the height and width of the image #9

Closed
moinmail opened this issue Mar 22, 2016 · 1 comment
Closed

How i can get the height and width of the image #9

moinmail opened this issue Mar 22, 2016 · 1 comment

Comments

@moinmail
Copy link

I have to use height and width of the image to resize the uiimageview. but i am unable to get the height and width of the image.

there is no option to get the height and width. below is my code. i want to assign image height and width instead of static values (width: 355, height: 200)

objImgview.loadImageFromURLString(strURLN, placeholderImage: UIImage(named: "KiavashFaisali")) {
(finished, potentialError) in
if finished {
objImgview.frame = CGRect(x: 0, y: CGFloat(imgPosteryPoss), width: 355, height: 200 )
}
else if let error = potentialError {
print("error occurred with description: (error.localizedDescription)")
}
}

@kiavashfaisali
Copy link
Owner

Hello, thank you for posting this, I think many people would be interested to dynamically size the UIImageView based on the exact size of the UIImage loaded within.

KFSwiftImageLoader won't need to provide any additional information in this case since you can access the UIImage directly (via the "image" property on the UIImageView) from within the completion block and get its size per documentation: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/index.html#//apple_ref/occ/instp/UIImage/size

Alternatively, the documentation on UIImageView states that you can call "sizeToFit()" on the image view to get it to auto-resize to adapt to the size of the UIImage within.
Documentation for reference on that topic is here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImageView_Class/index.html#//apple_ref/occ/instp/UIImageView/image

Please let me know if either of these two methods worked for you.

Regards,
Kiavash

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