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