Use of Swift-uiimageview

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.