iOS uiimageview handling picture size issues

Source: Internet
Author: User

    • Uiimageview view can display pictures
      There are two methods of instantiating Uiimageview
      The first method: Uiimageview *myimageview = [[Uiimageview alloc] Initwithimage: [UIImage imagenamed: @ "demo"]];
      Use this method to display the original size of the picture.

      Second method: Uiimageview *myimageview = [[UIImage alloc] initWithFrame:self.view.bounds]
      This method displays the picture at a specified size, regardless of the original size of the picture, causing the picture to deform.

In many cases, you need to place the picture in a range of a specified size and not distort the picture. Resolve the issue to set the Contentmode property of the Uiimageview. Contentmode is an enumeration:

typedef NS_ENUM(NSInteger, UIViewContentMode){    UIViewContentModeScaleToFill,    UIViewContentModeScaleAspectFit,    UIViewContentModeScaleAspectFill,    UIViewContentModeRedraw,    UIViewContentModeCenter,    UIViewContentModeTop,    UIViewContentModeBottom,    UIViewContentModeLeft,    UIViewContentModeRight,    UIViewContentModeTopLeft,    UIViewContentModeTopRight,    UIViewContentModeBottomLeft,    UIViewContentModeBottomRight};

The three most commonly used modes are:

Uiviewcontentmodescalefill: The picture will be filled in the picture view;
Uiviewcontentmodescaleaspectfit: Will make the picture with the original aspect ratio to adapt to the picture view;
Uiviewcontentmodescaleaspectfill: First to set the Clipstobounds property of the picture view to Yes, so that the image fills the entire picture view with its original aspect ratio, and the excess part will be clipped out;
So the general Set Picture view mode is Uiviewcontentmodescaleaspectfit.

iOS uiimageview handling picture size issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.