Uiimageview and UIImage Swift Learning

Source: Internet
Author: User
Tags border color

//

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

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.