1. Create
var imageView = Uiimageview ()// initialization
2, the picture display and the picture change
" Hgl.jpeg " = CGRectMake (self.view.addSubview) (ImageView)
3. How to get Pictures
(1) Get from file directory
Using the NSBundle class
(2) Get from the network address (interested friends can try it yourself)
4, to achieve the playback of animation
Uiimageview provides the ability to store multiple pictures to create animations by setting an array of pictures in the Animationimages property and then starting the animation using the Startanimating method. Finally, stop the animation with the Stopanimating method. Also, use the Animationduration property to set the speed, in seconds, for the animation to toggle per frame.
// Animate playback using image controls Imageview.animationimages = [UIImage (named:"hgl.jpeg")!,uiimage (named:" 11.jpg")! ] // set each 0.5-second change 0.5 // keep picture proportions Imageview.contentmode =. Scaleaspectfit
Calls to animations
Override func viewwillappear (animated:bool) { super.viewwillappear (animated) imageview.startanimating () } Override func viewwilldisappear (animated:bool) { super.viewwillappear (animated) imageview.stopanimating () }
5, maintain the proportion of the picture
The default Uiimageview stretches the picture so that it fills the entire uiimageview, and if you don't want the picture to deform, you can set the Contentmode to aspect Fit.
Imageview.contentmode =. Scaleaspectfit
The effect is as follows
Use of Swift-uiimageview