如何快速圈出图片?
我的ViewController:
import UIKit import Foundation class FriendsViewController : UIViewController{ @IBOutlet weak var profilPicture: UIImageView! override func viewDidLoad() { super.viewDidLoad() profilPicture = UIImageView(frame: CGRectMake(0, 0, 100, 100)) } }
我profilPicture = UIImageView(frame: CGRectMake(0, 0, 100, 100))什么也没做..
profilPicture = UIImageView(frame: CGRectMake(0, 0, 100, 100))
范例:http://www.appcoda.com/ios-programming-circular-image- calayer/
import UIKit class ViewController: UIViewController { @IBOutlet weak var image: UIImageView! override func viewDidLoad() { super.viewDidLoad() image.layer.borderWidth = 1 image.layer.masksToBounds = false image.layer.borderColor = UIColor.black.cgColor image.layer.cornerRadius = image.frame.height/2 image.clipsToBounds = true }
如果要在扩展上使用
import UIKit extension UIImageView { func makeRounded() { self.layer.borderWidth = 1 self.layer.masksToBounds = false self.layer.borderColor = UIColor.black.cgColor self.layer.cornerRadius = self.frame.height / 2 self.clipsToBounds = true } }
那就是你所需要的。