swift UIImageView

/* swift 3.0    UIImageView的使用

 

         

*/

        var imageView = UIImageView.init(image: UIImage.init(named: "a.png"))

        imageView.center = view.center

        view.addSubview(imageView)

 

        

        /*  图片缩放策略   一般用scaleAspectFit

         

         case scaleToFill  /* 拉伸,充满背景 */

         

         case scaleAspectFit // contents scaled to fit with fixed aspect. remainder is transparent  /* 拉伸,不过是保证width充满,之后height等比拉伸 */

         

         case scaleAspectFill // contents scaled to fill with fixed aspect. some portion of content may be clipped./* 拉伸,保证小的先满足,再等比拉伸 */

         

         

         重绘,没用过

         case redraw // redraw on bounds change (calls -setNeedsDisplay)

         

         下面都是图不拉伸,且显示的位置

         case center // contents remain same size. positioned adjusted.

         case top

         case bottom

         case left

         case right

         case topLeft

         case topRight

         case bottomLeft

         case bottomRight

         */

        imageView.contentMode = .scaleAspectFit

        

        

        

        

        

        

        

        

        /* 图片圆角 */

        imageView.layer.masksToBounds = true;

        imageView.layer.cornerRadius  = 10;

        

        /* 从本地加载图片

         

            1. imageNamed方式

                此时加载的图片是带有缓存的

                而且此时系统能自动加载对应分辨率的图片

         

            2. contentsOfFiles方式

                此时图片不会被缓存

                此时需要自己设置一个字符串,去拼接图片,从而显示对应分辨率的图片

         

            虽然第二种方式看上去没那么方便,但是不带缓存,内存占用少;

            那么该如何选择了?

            1)不滑动,不能移动的页面 采用 contentsOfFiles

            2tableview,scrollView,collectionView等,需要快速滑动的 采用 imageNamed

         

            具有动态的页面,各种资源加载越快越好,所以采用缓存策略;

            而静态的页面,对fps影响不大,所以采用不带缓存的加载策略;

         */

        

        /* imageNamed */

        imageView.image = UIImage.init(named: "a.png")

        

        /* contentOfFiels */

        let path      = Bundle.main.path(forResource: "b", ofType: "png")

        let newImage  = UIImage.init(contentsOfFile: path!)

        imageView.image = newImage

        

        

        

        

        

        

        /* 图片帧动画 */

        imageView.animationImages = [UIImage.init(named: "a.png")!,UIImage.init(named: "b.png")!]

        imageView.animationDuration = 0.5

        imageView.startAnimating()

        imageView.animationRepeatCount = 1000

//        open func stopAnimating()   停止动画

//        open var isAnimating: Bool { get }  动画是否正在进行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值