//
Viewcontroller.swift
Uiimageview and UIImage
//
Created by Mac on 15/4/12.
Copyright (c) year BSY. All rights reserved.
//
Import UIKit
class Viewcontroller:uiviewcontroller {
Override func viewdidload () {
Super. Viewdidload ()
// loading of local images
Self. AddImage ()
// Load Network pictures (not local)
self. Addremoteimageview ()
}
func AddImage ()
{
// initialize Uiimageview and UIImage
var uimageview = Uiimageview (Frame:cgrectmake (+,+, +) )
// settings to load a local picture
Let image = UIImage (named:"Cat.jpg")
// throw the loaded image to the image display in ImageView
Uimageview.image = Image
// load the Uiimageview onto the parent control, i.e. Self.view
self. View.addsubview (Uimageview)
}
// Load Network pictures (not local)
func Addremoteimageview ()
{
var imageView = Uiimageview (Frame:cgrectmake (+,+, +) )
// Image Address
let strurl ="http://e.hiphotos.baidu.com/baike/c0%3Dbaike80%2C5%2C5%2C80%2C26/sign= 410619fb3d01213fdb3e468e358e5db4/9f510fb30f2442a71525d087d543ad4bd11302ec.jpg "
//url
Let url = Nsurl (string:strurl)
// Picture Data
var data = NSData (contentsofurl:url!)
// by getting picture data to load
Let image = UIImage (data:data!)
// Drop the loaded image to ImageView 's image reality
Imageview.image = Image
// border color settings
ImageView.layer.borderColor = Uicolor.redcolor (). Cgcolor
// width setting of the border
ImageView.layer.borderWidth =2
// rounded corners of the set
ImageView.layer.cornerRadius =
//The most important sentence
ImageView.layer.masksToBounds =true
// load the Uiimageview onto the parent control, i.e. Self.view
self. View.addsubview (ImageView)
}
Override func didreceivememorywarning () {
Super. didreceivememorywarning ()
//Dispose of any resources, can be recreated.
}
}
Uiimageview and UIImage Swift Learning