UIImageView
1 override func viewDidLoad() { 2 super.viewDidLoad() 3 4 titleLabel.text = titleString 5 6 //通过坐标和大小来创建图像视图 7 var imageView:UIImageView = UIImageView(frame: CGRectMake(20, 100, 90, 90)) 8 imageView.image = UIImage(named: "SwiftClassWeiXin.png") 9 self.view.addSubview(imageView) 10 11 12 //通过图片来初始化大小 13 var imageView2:UIImageView = UIImageView(image: UIImage(named: "SwiftClassWeiXin.png")) 14 imageView2.frame = CGRectMake(20, 200, 90, 90) 15 self.view.addSubview(imageView2) 16 17 18 var image:UIImage! = UIImage(named: "SwiftClassWeiXin.png") 19 20 21 //从文件路径得到图片,type是指文件后缀 22 23 //定义路径 24 let path : String? = NSBundle.mainBundle().pathForResource("SwiftClassWeiXin1", ofType: "png") 25 26 //解包 27 if let sValue = path { 28 var newImage:UIImage! = UIImage(contentsOfFile: sValue) 29 } 30 31 32 //从网络地址获取图片 33 34 //定义一个地址字符串常量 35 let imageUrlString:String = "http://www.iphonetrain.com/core/res/images/logo.png"; 36 37 //通过String类型,转换成NSUrl对象 38 let url:NSURL! = NSURL(string: imageUrlString) 39 40 //从网络获取数据流 41 var data:NSData! = NSData(contentsOfURL: url) 42 43 //通过数据流初始化图片 44 var newImage2:UIImage! = UIImage(data: data) 45 46 imageView2.image = newImage2 47 48 49 imageView2.contentMode = UIViewContentMode.Center 50 51 52 53 //定义图片名数组 54 var imageArray:[UIImage]! = [ 55 UIImage(named: "1kar1.png")!, 56 UIImage(named: "1kar2.png")!, 57 UIImage(named: "1kar3.png")!, 58 UIImage(named: "1kar4.png")!, 59 UIImage(named: "1kar5.png")!, 60 UIImage(named: "1kar6.png")!, 61 UIImage(named: "1kar7.png")!, 62 UIImage(named: "1kar8.png")!, 63 UIImage(named: "1kar9.png")!, 64 UIImage(named: "1kar10.png")!, 65 UIImage(named: "1kar11.png")!, 66 UIImage(named: "1kar12.png")!, 67 UIImage(named: "1kar13.png")!] 68 69 70 //设置图像视图的animationImages属性 71 imageView2.animationImages = imageArray 72 73 //设置动画时间 74 imageView2.animationDuration = 5.0 75 76 //设置动画播放次数 77 imageView2.animationRepeatCount = 2 78 79 //开始播放动画 80 imageView2.startAnimating() 81 82 83 // [self.aImageView setIsAccessibilityElement:YES]; 84 // [self.aImageView setAccessibilityLabel:self.title]; 85 86 }
时间: 2024-10-13 11:55:45