IOS Swift Module Exercises

Source: Internet
Author: User

1, Uiimageview + UIImage

Import UIKitclassUiimageviewviewcontroller:uiviewcontroller {var imageView=Uiimageview () var imagechangeview=Uiimageview ()Overridefunc viewdidload () {super.viewdidload ()//Do any additional setup after loading the view.Self . Creatui ()//Create a ImageView local file in the network picture getSelf . Changeimage ()} func changeimage () {imagechangeview.frame= CGRect (x: -Y: -, Width: $, Height: $) Imagechangeview.backgroundcolor=Uicolor.blue//Set AnimationImagechangeview.animationimages = [UIImage (named:"1.jpg")!,uiimage (named:"2.jpg")!,uiimage (named:"3.jpg")!,uiimage (named:"4.jpg")!]                //set the cycle time to 1 seconds per intervalImagechangeview.animationduration =4        //Keep picture scale \ Default Uiimageview will stretch the picture so that it fills the entire uiimageview, if you do not want to distort the picture, you can set the Contentmode to Tofill full Iamgeview, Aspectfit ImageView in the original proportion. Aspectfill shows the original proportions, the insufficient ImageView expandsImagechangeview.contentmode =. Scaletofill Self.view.addSubview (Imagechangeview) imagechangeview.startanimating ()} func Cr Eatui () {//ImageView CreateImageView = Uiimageview (Image:uiimage (named:"1.jpg")) Imageview.frame= CGRect (x: -Y: -, Width: $, Height: $) Self.view.addSubview (ImageView)//Modify a pictureImageview.image = UIImage (named:"2.jpg")                        //get pictures in the catalogLet path = Bundle.main.path (Forresource:"3", OfType:"jpg") Imageview.image= UIImage (contentsoffile:path!)                        //Network Download PicturesLet URL = URL (string:"Http://hangge.com/blog/images/logo.png") Let data=Try! Data (contentsof:url!)//get data stream online//initializing a picture with a flow of waterLet NewImage =UIImage (data:data) imageview.image=NewImage}Overridefunc didreceivememorywarning () {super.didreceivememorywarning ()//Dispose of any resources the can be recreated.    }       }

IOS Swift Module Exercises

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.