I seen in many posts for resizing the image by keeping aspect ratio. These functions uses the fixed points(Width and Height) for RECT while resizing. But in my project, I need to resize the view based on the Width alone, Height should be taken automatically based on the aspect ratio. anyone help me to achieve this.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
This method is a category on UIImage. Does scale to fit in few lines of code using AVFoundation. Don't forget to import
#import <AVFoundation/AVFoundation.h>
.Programmatically:
Storyboard:
Well, we have few good answers here for resizing image, but I just modify as per my need. hope this help someone like me.
My Requirement was
You may like to check this as well for resize calculation.
When scale is set to 0.0, the scale factor of the main screen is used, which for Retina displays is 2.0 or higher (3.0 on the iPhone 6 Plus).
This one was perfect for me. Keeps aspect ratio and takes a
maxLength
. Width or Height will not be more thanmaxLength
Calculates the best height of the image for available width.