码迷,mamicode.com
首页 > 其他好文 > 详细

UIImageView

时间:2015-11-19 11:06:14      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:

创建ImageView

let imageView = UIImageView(frame: CGRectMake(10, 100, self.view.frame.size.width-20, 400))
imageView.backgroundColor = UIColor.orangeColor()
imageView.tag = 101
imageView.image = UIImage(named: "0")
imageView.contentMode = .ScaleAspectFit//保持图片比例
self.view.addSubview(imageView)

从文件中获取图片

let path = NSBundle.mainBundle().pathForResource("1", ofType: "png")
if let newPath = path{
    imageView.image = UIImage(contentsOfFile: newPath)
}

从网络获取图片

let url = NSURL(string: "http://ww2.sinaimg.cn/bmiddle/632dab64jw1ehgcjf2rd5j20ak07w767.jpg")
let data = NSData(contentsOfURL: url!)
if let newData = data {
    imageView.image = UIImage(data: newData)
}

多张图片播放动画

let image1 = UIImage(named:"0")!
let image2 = UIImage(contentsOfFile: path!)!
let image3 = UIImage(data: data!)!
var array  = [UIImage]()
array.append(image1)
array.append(image2)
array.append(image3)

imageView.animationImages = array
imageView.animationDuration = 1
imageView .startAnimating()//开始
imagev.stopAnimating()//停止

  

UIImageView

标签:

原文地址:http://www.cnblogs.com/spaceID/p/4976689.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!