How can i make i circle picture with swift ?
My ViewController :
import UIKit
import Foundation
class FriendsViewController : UIViewController{
This way is the least expensive way and always keeps your image view rounded:
class RoundedImageView: UIImageView {
override init(frame: CGRect) {
super.init(frame: frame)
clipsToBounds = true
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
clipsToBounds = true
}
override func layoutSubviews() {
super.layoutSubviews()
assert(bounds.height == bounds.width, "The aspect ratio isn't 1/1. You can never round this image view!")
layer.cornerRadius = bounds.height / 2
}
}
The other answers are telling you to make views rounded based on frame calculations set in a UIViewControllers viewDidLoad() method. This isn't correct, since it isn't sure what the final frame will be.