GPAvatarView 0.4.0

GPAvatarView 0.4.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Oct 2016
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Gabriele Petronella.



GPAvatarView

A deadly simple UIView subclass for rounded corners lazy-loaded images.

Pure swift code.

It loads and renders a UIImage lazyily from a URL, optionally specifying a placeholder image.

Interface Builder support

You can use GPAvatarImage directly from Interface Builder, dragging a UIView into your view hierarchy and chaning its class to GPAvatarImage. The view is fully compliant with Xcode 6 Live Rendering feature, so you can preview the image and set a placeholder directly from IB.

Needless to say, you can otherwise use this component programmatically.

API

There’s a single method you can call:

func setImageWithURL(
  URL: NSURL,
  placeholder: UIImage? = nil,
  completionHandler:((UIImage!, NSError?) -> Void)? = nil
)

as you see the only required parameter is URL. placeholder and completionHandler are optional.

Quick example

let url = NSURL(string: "https://example.com/foo.jpg")
let placeholder = UIImage(named: "placeholder")

avatarView.setImageWithURL(url, placeholder: placeholder) { (image, error) in
  if let e = error {
    println("Houston, we have a problem: \(e)")
  } else {
    // do whatever you like with your damn image
  }
}

Credits