[IOS]今天开始学UI---UIImageView

UIImageView的作用:UIImageView可以看作图片的专用容器,可以用来展示单个图片或者一些列图片。

当展示一系列图片的时候 可以通过设置动画时长,同时也能随时停止动画和开始动画。展示一系列图片 的动画效果就像幻灯片一样。

NS_CLASS_AVAILABLE_IOS(2_0) @interface UIImageView : UIView {
  @private
    id _storage;
}

- (instancetype)initWithImage:(UIImage *)image;
- (instancetype)initWithImage:(UIImage *)image highlightedImage:(UIImage *)highlightedImage NS_AVAILABLE_IOS(3_0);

@property(nonatomic,retain) UIImage *image;                                                     // default is nil
@property(nonatomic,retain) UIImage *highlightedImage NS_AVAILABLE_IOS(3_0);      // default is nil
@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;               // default is NO

@property(nonatomic,getter=isHighlighted) BOOL highlighted NS_AVAILABLE_IOS(3_0); // default is NO

// these allow a set of images to be animated. the array may contain multiple copies of the same

@property(nonatomic,copy) NSArray *animationImages;            // The array must contain UIImages. Setting hides the single image. default is nil
@property(nonatomic,copy) NSArray *highlightedAnimationImages NS_AVAILABLE_IOS(3_0);            // The array must contain UIImages. Setting hides the single image. default is nil

@property(nonatomic) NSTimeInterval animationDuration;         // for one cycle of images. default is number of images * 1/30th of a second (i.e. 30 fps)
@property(nonatomic) NSInteger      animationRepeatCount;      // 0 means infinite (default is 0)

// When tintColor is non-nil, any template images set on the image view will be colorized with that color.
// The tintColor is inherited through the superview hierarchy. See UIView for more information.
@property (nonatomic, retain) UIColor *tintColor NS_AVAILABLE_IOS(7_0);

- (void)startAnimating;
- (void)stopAnimating;
- (BOOL)isAnimating;

@end

可以说  UIImageView是图片的容器  里面存放着一系列的图片 苹果官方推荐图片使用的格式为png

@property(nonatomic,retain) UIImage *image;//单个图片
@property(nonatomic,retain) UIImage *highlightedImage//当UIImageView highlighted = YES的时候 将展示的图片
@property(nonatomic,copy) NSArray *animationImages; //一组图片 
@property(nonatomic,copy) NSArray *highlightedAnimationImages//当UIImageView highlighted = YES的时候 将展示的图片


如果同时设置image 属性和animationImages 属性的时 不显示 image 但是 animationImages 再重新设置为nil的时候 imaget又重新出现了

同时如果设置backgroundColor是无效的?并不能显示 哪怕一张图片都没有


UIImageView 并不能响应用户所进行的触碰等行为 是因为 userInteractionEnabled 属性默认设置为NO

如果要使其响应触碰行为 只要设置YES即可


使用UIImageView也和其他的View相同

1.创建

单图片UIImageView创建

- (instancetype)initWithImage:(UIImage *)image;
- (instancetype)initWithImage:(UIImage *)image highlightedImage:(UIImage *)highlightedImage
如果要创建多图片UIImageView只要在创建后 setAnimationImages

UIImageView 继承自UIView所以父类的初始化方式 也是支持的

比如

- (instancetype)initWithFrame:(CGRect)aRect
设置是其更之上的父类NSObject的

- (instancetype)init;


所有的UIView或者继承自UIView的View都是支持以上两种方式初始化的


现在我们创建一个能播放一组图片的UIImageView

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    UIImageView *imageView = [[UIImageView alloc] init];
    //UIImageView的 animationImages 的属性类型是 NSArray 所以我们我们传入的也是NSArray
    NSMutableArray *images = [NSMutableArray array];
    for (int i=1; i<6; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%i.png",i]];
        [images addObject:image];
    }
    [imageView setAnimationImages:images];

    imageView.frame = CGRectMake(50, 50, 200, 200);
    //指定一组图片播放完需要的时间
    [imageView setAnimationDuration:2.0f];
//  [imageView setAnimationRepeatCount:10]; 默认是不停的重复播放 如果不指定值的话

    [self.view addSubview:imageView];
    //开始播放图片
    [imageView startAnimating];



}


突然发现 需要单独做一期 关于UIView 的transform属性 和contentMode属性的介绍

该两种属性 关于 UIView的动作行为 比如缩放 旋转等转换行为 contentMode 则是关于UIView中的内容是如何摆放的问题

以上两种属性 都是UIView的 并不是属于该UIImageView特有的属性 也就是基本上所有的继承自UIView的View都是能够使用的

但是关于图片需要做的duang效果比较多  所以也就只能再下一篇讲了



that's all

thx



Everything you see on Screen is UIView.





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值