Use of UIImageView, use of UIImageView

Source: Internet
Author: User

Use of UIImageView, use of UIImageView

// Create an imageView

UIImageView x imgView = [[UIImageViewalloc] initWithFrame: CGRectMake (100,100,200,280)];

ImgView. backgroundColor = [UIColorredColor];

// Set the displayed image. The default suffix is png.

UIImage * image = [UIImageimageNamed: @ "1"];

ImgView. image = image;

// Set the highlighted Image

ImgView. highlightedImage = [UIImageimageNamed: @ "scene1.jpg"];

// ImgView. highlighted = YES;

// Border processing

ImgView. layer. borderWidth = 1;

ImgView. layer. borderColor = [UIColorgreenColor]. CGColor;

ImgView. layer. cornerRadius = 5;

// Set the filling mode of the image. UIViewContentModeScaleAspectFit: proportional stretch of the image.

ImgView. contentMode = UIViewContentModeScaleAspectFit;

[_ Window addSubview: imgView];

// ImgView. animationImages =

NSMutableArray * imgArray = [[NSMutableArrayalloc] init];

For (int I = 1; I <22; I ++ ){

NSString * imgName = [NSStringstringWithFormat: @ "mongod.jpg", I];

UIImage * img = [UIImageimageNamed: imgName];

// Set the image stretch point of UIImage

// Img resizableImageWithCapInsets: UIEdgeInsetsMake (from top, left, bottom, right );

[ImgArray addObject: img];

}

// Sets an animation set for the imgView.

ImgView. animationImages = imgArray;

// Set the animation time

ImgView. animationDuration = 5;

// Start the animation

[ImgView startAnimating];

UIButton * button = [UIButtonbuttonWithType: UIButtonTypeContactAdd];

Button. frame = CGRectMake (20, 20, 20, 20 );

[Button addTarget: selfaction: @ selector (buttonAction) forControlEvents: UIControlEventTouchUpInside];

[ImgView addSubview: button];

// Note: When adding a click event in UIImageView, you must change it to yes.

ImgView. userInteractionEnabled = YES;

Return YES;

}


-(Void) buttonAction {


NSLog (@ "the button is clicked ");

}


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.