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 ");
}