Image is not fit to the frame of UIImageView
I am creating the
UIImageView using interface Builder. Its frame size is (320,67).
I want to display the image on the imageView. I am getting the image from the web. The problem is that the image get from web is stretched to display on the imageview…
Here my code
NSData *imageData=[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.isco.com/webproductimages/appBnr/bnr1.jpg"]]; imageView.image = [UIImage imageWithData:imageData];
Can anyone tel me that how to display the image fit to display on imageView????
- Cannot assign to property in protocol - Swift compiler error
- Using Private API To read WiFi RSSI Value
- Indent second line of UILabel
- NSCoding required initializer in inherited classes in Swift
- QRCode Scanner Not Working in iOS 11, only showing camera preview
- Stop reloading of web app launched from iPhone Home Screen
4 Solutions Collect From Internet About “Image is not fit to the frame of UIImageView”
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.contentMode = UIViewContentModeScaleAspectFit;
The first one will fill the frame, possibly cutting off parts of your image. The second one will show the entire image, possibly leaving areas of the frame open.
For Swift :
imageView.contentMode = UIViewContentMode.ScaleAspectFit
For Objective-C :
imageView.contentMode = UIViewContentModeScaleAspectFit
ScaleAspectFit option is use to scale the content to fit the size of the view by maintaining the aspect ratio. Any remaining areas of the view’s bounds is transparent.
Refer Apple docs for details.
Try this code.
imView.contentMode = UIViewContentModeScaleAspectFit;
I ended up resizing the image after the image was scaled according to it’s aspect ratio.
let widthRatio = ImageView.bounds.size.width / (captureImageView.image?.size.width)! let heightRatio = ImageView.bounds.size.height / (captureImageView.image?.size.height)! let scale = min(widthRatio, heightRatio) let imageWidth = scale * (ImageView.image?.size.width)! let imageHeight = scale * (ImageView.image?.size.height)! ImageView.frame = CGRect(x: 0, y: 0, width: imageWidth, height: imageHeight)
- xcode custom ttf font not working
- Why does having more than one capture group in my regex crash my app?
- How do I list all fields of an object in Objective-C?
- How to add string objects to NSMutableArray
- Could not get the server error message from Alamofire 3.3.0
- Misaligned Sound Playback using AVPlayer and AVMutableComposition
- Reading from txt file in Swift 3
- UIScrollView image/photo viewer with paging enabled and zooming
- Converting a CGRect of a object in a subview in UITableViewCell in UITable to CGRect with respect to self.view
- Custom Tab Bar Controller with Navigation Bar
- Multiple IBOutlets in same line of same type in Swift
- whose view is not in the window hierarchy
- New iPhone App – How to Choose which Xcode Template to Use?
- Table view is not displaying the comments or username from Firebase
- Solve Equations Of Type A*X = B Using dgtsv_ or sgtsv_