//
// ViewController.swift
// UIImageview and UIImage
//
// Created by Mac on 15/4/12.
// Copyright (c) 2015Äê BSY. All rights reserved.
//
?
import UIKit
?
class ViewController: UIViewController {
?
override func viewDidLoad() {
super.viewDidLoad()
// ±¾µØÍ¼Æ¬µÄ¼ÓÔØ
// self .addimage()
?
//¼ÓÔØÍøÂçͼƬ£¨·Ç±¾µØ£©
self.addRemoteImageView()
}
?
func addimage()
{
// ³õʼ»¯uiimageview and uiimage
var uimageview = UIImageView(frame: CGRectMake(35, 100, 300, 300))
//ÉèÖüÓÔØÒ»Õű¾µØÍ¼Æ¬
let image = UIImage(named:"cat.jpg")
//°Ñ¼ÓÔØºÃµÄͼƬ¶ª¸øimageviewÖеÄimageÏÔʾ
uimageview.image = image
//°Ñuiimageview¼ÓÔØµ½¸¸¿Ø¼þÉÏ£¬Ò²¾ÍÊÇself.view
self.view.addSubview(uimageview)
?
?
?
?
}
//¼ÓÔØÍøÂçͼƬ£¨·Ç±¾µØ£©
func addRemoteImageView()
{
var imageView = UIImageView(frame: CGRectMake(35, 100, 300, 300))
// ͼƬµØÖ·
let strUrl = "https://www.cppentry.com/upload_files/article/49/1_q4ua8__.jpg"
//url
let url = NSURL(string: strUrl)
//ͼƬÊý¾Ý
var data = NSData(contentsOfURL:url!)
//ͨ¹ýµÃµ½Í¼Æ¬Êý¾ÝÀ´¼ÓÔØ
let image = UIImage(data: data!)
//°Ñ¼ÓÔØµ½µÄͼƬ¶ª¸øimageViewµÄimageÏÖʵ
imageView.image = image
?
//±ß¿òÑÕÉ«ÉèÖÃ
imageView.layer.borderColor = UIColor.redColor().CGColor
//±ß¿òµÄ¿í¶ÈÉèÖÃ
imageView.layer.borderWidth = 2
?
//Ô²½ÇµÄÉèÖÃ
imageView.layer.cornerRadius = 150
?
// ×îÖ÷ÒªµÄÒ»¾ä
imageView.layer.masksToBounds = true
//°Ñuiimageview¼ÓÔØµ½¸¸¿Ø¼þÉÏ£¬Ò²¾ÍÊÇself.view
self.view.addSubview(imageView)
?
?
?
?
?
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
?
?
}
?