I need to display a profile pic of every user corresponding to his name in a UITableView. Until the image is downloaded I need to show an image with his name\'s first alphabet l
"NO NEED ANY FRAMEWORK"
"Its Work Wonderfully"
@IBOutlet weak var IBtxtFieldName:UITextField!
@IBOutlet weak var IBtxtFieldSurname:UITextField!
@IBOutlet weak var IBImgViewUserProfile:UIImageView!
@IBAction func IBbtnShowTapped(sender: UIButton)
{
let lblNameInitialize = UILabel()
lblNameInitialize.frame.size = CGSize(width: 100.0, height: 100.0)
lblNameInitialize.textColor = UIColor.whiteColor()
lblNameInitialize.text = String(IBtxtFieldName.text!.characters.first!) + String(IBtxtFieldSurname.text!.characters.first!)
lblNameInitialize.textAlignment = NSTextAlignment.Center
lblNameInitialize.backgroundColor = UIColor.blackColor()
lblNameInitialize.layer.cornerRadius = 50.0
UIGraphicsBeginImageContext(lblNameInitialize.frame.size)
lblNameInitialize.layer.renderInContext(UIGraphicsGetCurrentContext()!)
IBImgViewUserProfile.image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
}
"SWIFT 3.0"
@IBAction func IBbtnShowTapped(sender: UIButton)
{
let lblNameInitialize = UILabel()
lblNameInitialize.frame.size = CGSize(width: 100.0, height: 100.0)
lblNameInitialize.textColor = UIColor.white
lblNameInitialize.text = String(IBtxtFieldName.text!.characters.first!) + String(IBtxtFieldSurname.text!.characters.first!)
lblNameInitialize.textAlignment = NSTextAlignment.center
lblNameInitialize.backgroundColor = UIColor.black
lblNameInitialize.layer.cornerRadius = 50.0
UIGraphicsBeginImageContext(lblNameInitialize.frame.size)
lblNameInitialize.layer.render(in: UIGraphicsGetCurrentContext()!)
IBImgViewUserProfile.image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
}
I've written a Swift library for this : https://github.com/ayushn21/AvatarImageView
It's highly customisable and uses a protocol oriented approach to get it's data and configuration