iOS 教程教程
IOS图像视图(Image View)
IOS图像视图(Image View)
图像视图的使用
图像视图用于显示单个图像或动画序列的图像。
重要的属性
- image
- highlightedImage
- userInteractionEnabled
- animationImages
- animationRepeatCount
重要的方法
- (id)initWithImage:(UIImage *)image
- (id)initWithImage:(UIImage *)image highlightedImage: (UIImage *)highlightedImage
- (void)startAnimating
- (void)stopAnimating
添加自定义方法 addImageView
-(void)addImageView{
UIImageView *imgview = [[UIImageView alloc]
initWithFrame:CGRectMake(10, 10, 300, 400)];
[imgview setImage:[UIImage imageNamed:@"AppleUSA1.jpg"]];
[imgview setContentMode:UIViewContentModeScaleAspectFit];
[self.view addSubview:imgview];
}
添加另一个自定义方法 addImageViewWithAnimation
这种方法解释了如何对imageView 中的图像进行动画处理
-(void)addImageViewWithAnimation{
UIImageView *imgview = [[UIImageView alloc]
initWithFrame:CGRectMake(10, 10, 300, 400)];
// set an animation
imgview.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"AppleUSA1.jpg"],
[UIImage imageNamed:@"AppleUSA2.jpg"], nil];
imgview.animationDuration = 4.0;
imgview.contentMode = UIViewContentModeCenter;
[imgview startAnimating];
[self.view addSubview:imgview];
}
注意: 我们必须添加命名为"AppleUSA1.jpg"和"AppleUSA2.jpg"到我们的项目,可以通过将图像拖到我们导航区域,其中列出了我们的项目文件所做的图像。
在 ViewController.m 中更新 viewDidLoad,如下所示
(void)viewDidLoad
{
[super viewDidLoad];
[self addImageView];
}
| IOS图像视图(Image View) |
|---|
iOS 教程
IOS 是苹果公司研发的一款手机操作系统。IOS 具有简单易用的界面、令人惊叹的功能,以及超强的稳定性,是 iPad、iPhone、iPod touch和 Apple TV 的操作系统。
加载中,请稍侯......