Ios-based UIImageView and iosuiimageview

Source: Internet
Author: User

Ios-based UIImageView and iosuiimageview

UIImageView

UIImageView is a subclass of UIView. Its main function is to display images.

Create a UIImage object

UIImage*Image= [UIImageimageNamed:@ "Qwer.jpg"];

Create a UIImageView object imageView. The initialization method is initWithImage :.

You must pass a parameter of the UIImage type. This parameter is the image to be displayed in the imageView.

Upload the created image.

UIImageView*ImageView= [[UIImageView alloc]InitWithImage:Image];

Add the imageView to the parent view.

[Self.View addSubView:ImageView];

UIImageCommon creation methods

1. UIImage * image = [UIImage imageNamed: @ "1.jpg"];

Small images are often used. They are first loaded into the cache and then returned.

2. UIImage * image = [UIImage imageWithContentsOfFile: path];

UIImageView * imageView = [[UIImageView alloc] initWithImage: image];

Large images are not frequently used and are not cached

 

 

Select imageView to display the image Style

UIImageView provides a variety of image display styles, by the UIViewContentMode attribute con

TentMode. UIViewContentMode is an enumeration type and provides 13 styles.

 

Three Common display modes: UIViewContentModeScaleToFill, UIViewContentModeScaleAspectFit, UIViewContentModeScaleAspectFill, and UIViewContentModeScaleToFill assign different image display effects to the contentMode attribute of imageView.

1, imageView. contentMode = UIViewContentModeScaleToFill;

The image will be filled with the entire imageView, and the entire image will be fully displayed,

Because the aspect ratio of the original image is different from that of the imageView, the image will be deformed,

2, imageView. contentMode = UIViewContentModeScaleAspectFit;

The image is completely displayed, and the entire image maintains the aspect ratio, but the image is reduced

So the imageView is not filled with images,

3, imageView. contentMode = UIViewContentModeScaleAspectFill;

The image will maintain the aspect ratio and original size, but will not be completely displayed by the imageView

 

 

ImageViewFrame

Set the imageView position and size

ImageView. frame = CGRectMake (CGFloat x, CGFloat y, CGFloat width, CGFloat height );

If no imageView frame is set, it will be the same as the image

 

 

 

 

Statement: Reference Dane notes

 

 

 

Related Article

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.