美文网首页OC 积累
iOS开发UI篇-常用控件详解(UIImageView)

iOS开发UI篇-常用控件详解(UIImageView)

作者: willphonez | 来源:发表于2016-07-20 16:39 被阅读747次

一.常用属性


  • 1、image: default is nil。图片属性
  • image的格式可以是.png或者.jpg的,但是后缀名为.jpg格式的图片只能放Assets.xcassets文件夹里才有效,而.png格式的图片放外面也可以.
  • 图片的两种加载方式
  • 有缓存
    UIImage *image =[UIImage imageNamed:@"图片名"];
    使用场合:图片比较小、使用频率比较高
    建议:把需要缓存的图片放到Assets.xcassets
  • 没有缓存
    NSString *file = [[NSBundle mainBundle] pathForResource:@"图片名" ofType:@"图片扩展名"];
    UIImage *image = [UIImage imageWithContentOfFile:file];
    *只要方法名带有file的,都是传全路径
    使用场合:图片比较大,使用频率比较低
    建议:不需要缓存的图片不能放在Assets.xcassets中
  • 放到Assets.xcassets中的图片只能通过图片名去加载,苹果会压缩图片,而且默认带有缓存
  • 2、highlightedImage: default is nil。高亮状态图片属性
  • 3、userInteractionEnabled: default is NO。用户是否可以交互属性
  • 4、highlighted: default is NO。判断图片是否是高亮状态
  • 5、 contentMode 内容模式,一般用来控制图片如何显示
typedef NS_ENUM(NSInteger, UIViewContentMode) {
    UIViewContentModeScaleToFill,
    UIViewContentModeScaleAspectFit,      // contents scaled to fit with fixed aspect. remainder is transparent
    UIViewContentModeScaleAspectFill,     // contents scaled to fill with fixed aspect. some portion of content may be clipped.
    UIViewContentModeRedraw,              // redraw on bounds change (calls -setNeedsDisplay)
    UIViewContentModeCenter,              // contents remain same size. positioned adjusted.
    UIViewContentModeTop,
    UIViewContentModeBottom,
    UIViewContentModeLeft,
    UIViewContentModeRight,
    UIViewContentModeTopLeft,
    UIViewContentModeTopRight,
    UIViewContentModeBottomLeft,
    UIViewContentModeBottomRight,
};
经验:
  • 1.带有scale单词的图片有可能被拉伸:
  • UIViewContentModeScaleToFill:将图片拉伸填充整个imageView;图片显示的 尺寸跟imageView的尺寸是一样的.
  • 2.带有scale单词的,并且带有aspect单词的:可能会被拉伸,但是会保持图片原来的宽高比
  • UIViewContentModeScaleAspectFit:保证刚好能看到图片的全部
  • UIViewContentModeScaleAspectFull:拉伸至图片的宽度或者高度跟imageView一样.
  • 3.不带有scale单词的,图片绝对不会被拉伸,保持图片原来的宽度和高度

下面属性允许图像组动画,该数组内可能包含相同的多个副本

  • 5、animationImages: 该数组当中必须包含多张图片,设置单张图片将被隐藏,默认 nil。
@property (nullable, nonatomic, copy) NSArray<UIImage *> *animationImages;
  • 6、highlightedAnimationImages: 高亮状态的组动画。
  • 7、animationDuration: 动画播放时间,对于一个周期的图像,默认的是图像是一秒30帧。
@property (nonatomic) NSTimeInterval animationDuration;
  • 8、animationRepeatCount: 0 means infinite (default is 0)。动画循环次数。0意味着无限(默认0,代表无限播放)。
@property (nonatomic) NSInteger  animationRepeatCount;
  • 9、tintColor: 给控件内子视图设置颜色。详细信息请见 UIImage类属性。

  • 10、focusedFrameGuide: 如果设置了adjustsImageWhenAncestorFocused,图像视图可以在一个更大的 frame 中显示其图片的焦点。这个布局指南,可用于将其他元素与图像视图的聚焦帧对齐。

@property(readonly,strong) UILayoutGuide *focusedFrameGuide;

二.常用方法


  • 1、initWithImage:: 构造方法,在初始化对象时直接进行默认图片进行赋值,默认尺寸就是图片的尺寸,位置默认从(0,0)开始。
 - (instancetype)initWithImage: (nullable UIImage *)image;
  • 2、initWithImage:highlightedImage:: 构造方法,在初始化对象时直接给默
    认和高亮图片进行赋值
 - (instancetype)initWithImage: (nullable UIImage *)image highlightedImage: (nullable UIImage *)highlightedImage;
  • 3、startAnimating:: 开始动画
 - (void)startAnimating;
  • 4、stopAnimating:: 结束动画
 - (void)stopAnimating;
  • 5、isAnimating:: 是否在动画中
 - (BOOL)isAnimating;

相关文章

网友评论

    本文标题:iOS开发UI篇-常用控件详解(UIImageView)

    本文链接:https://www.haomeiwen.com/subject/onvvjttx.html