A simple UIImageView extension for using initials as a profile image, written in swift

Overview

InitialsImageView

An easy, helpful UIImageView extension that generates letter initials as a placeholder for user profile images, with a randomized background color

Example screenshot

Installation

CocoaPods

Add this spec to your podfile:

pod "InitialsImageView"

Check out the official guide for getting started with CocoaPods.

Manual
  1. Drag the InitialsImageView.swift file into your project
  2. Enjoy!

Usage

Methods

Call the following methods on any UIImageView instance to set the image:

  • setImageForName(string: String, backgroundColor: UIColor?, circular: Bool, textAttributes: [String: AnyObject]?)

string is the string used to generate the initials. This should be a user's full name if available.

backgroundColor is an optional parameter that sets the background color of the image. Pass in nil to have a color automatically generated for you.

circular is a boolean parameter that will automatically clip the image to a circle if enabled.

textAttributes is an optional dictionary of predefined character attributes for text. You can find the list of available keys in NSAttributedString

Example
let randomImage: UIImageView = UIImageView.init(frame: CGRect(x: self.view.bounds.midX - 40, y: self.view.bounds.midY - 80 - 40, width: 80, height: 80))
randomImage.setImageForName(string: "Michael Bluth", backgroundColor: nil, circular: true, textAttributes: nil)

Saying Thanks

If you like this tool, show your support by downloading the free Turnout app that inspired it!

License

Using the MIT license. See license file for details.

Comments
  • Problem when implementing on UITableViewCell

    Problem when implementing on UITableViewCell

    I have implemented and UIImageView inside a subview on a UITableViewCell. The InitialsImage didn't show up until I scrolled and cell was reused. Any ideas? Thank you! ảnh ảnh ảnh ảnh

    opened by bigearsenal 5
  • Swift 4 problem

    Swift 4 problem

    All its working now with new commit. Thanks

    Hi,

    With Swift 4 we have a error:

    Value of type 'UIImageView' has no member 'setImageForName'

    Thanks a lot!

    opened by gitshell007 3
  • Request 0.8.0 tag and bump Podspec to match

    Request 0.8.0 tag and bump Podspec to match

    I forgot to do this in #19. Currently, the latest tag on the repo is 0.7.0, which doesn't include the SPM manifest—so SPM doesn't actually work if you try to specify a version.

    Even though there are no code changes, I'd like to request an 0.8.0 tag for SPM support—this single commit would bump the Podspec to match across the Pod and SPM.

    opened by synthemesc 2
  • Make random background color deterministic for a specific name

    Make random background color deterministic for a specific name

    With this PR, a given name will always get the same background color. This makes sense for my use case (using this thing for a hobby project atm, thanks for writing and publishing it!) and I imagine for many others.

    opened by skagedal 2
  • Add a support for backgrounds with gradient

    Add a support for backgrounds with gradient

    gradient is an optional boolean parameter. The colors for gradient can be generated automatically as offsets for the backgroundColor.

    Example randomImage.setImageForName(string: "Michael Bluth", backgroundColor: .cyan, circular: true, textAttributes: nil, gradient: true)

    Or with a random color: randomImage.setImageForName(string: "Michael Bluth", circular: true, textAttributes: nil, gradient: true)

    Another version of the setImageForName has an optional tuple named gradientColors. Thus it's possible to specify two explicit colors for the gradient.

    Example randomImage.setImageForName(string: "Michael Bluth", gradientColors: (top: .magenta, bottom: .purple), circular: true, textAttributes: nil)

    opened by vladvlasov256 1
  • Made extracting initials from string with nameInitials() more accurate.

    Made extracting initials from string with nameInitials() more accurate.

    Previously if non letter characters, such as John (Doe), were in the string it would extract the incorrect initials.

    Here are before and after tests: Passed String: John Old: J New: J Passed String: John Doe Old: JD New: JD Passed String: *** John Doe *** Old: ** New: JD Passed String: John (Doe) Old: J( New: JD Passed String: John Ron Long (Lucky) Doe Old: JD New: JD Passed String: &(#($)%))@^^%$ Old: & New:

    opened by tkeithblack 0
  • Problem for single String

    Problem for single String

    Everything works fine for "John do" but only "John" give nothing.

    var nameComponents = string.uppercased().components(separatedBy: CharacterSet.letters.inverted)

    nameComponents is nil with only "John". I don't know if it's expected but would be nice to get only a J in this case

    opened by SmartHbdev 0
  • Add Dark Mode support

    Add Dark Mode support

    Hi, first of all, thank you for this library :)

    Currently the background color doesn't get updated if the user switches between light and dark mode. This is because of using cgColor, which doesn't automatically update.

    enhancement 
    opened by ohetzendorfer 2
  • Crash

    Crash

    Crashed: com.apple.main-thread 0 InitialsImageView 0x1066d8f44 specialized UIImageView.imageSnapshot(text:backgroundColor:circular:textAttributes:gradient:gradientColors:) + 74 (InitialsImageView.swift:74) 1 InitialsImageView 0x1066d6364 UIImageView.setImageForName(_:backgroundColor:circular:textAttributes:gradient:gradientColors:) () 2 SocialBoards 0x104935390 closure #1 in UIImageView.downloadFrom(link:contentMode:rounded:loader:lettersToAssign:backgroundColor:) + 4373861264

    cannot reproduce 
    opened by Pirokar 1
Releases(0.7.0)
Owner
Tom Bachant
Tom Bachant
An extension that gives UIImageView the ability to focus on faces within an image.

FaceAware Sometimes the aspect ratios of images we need to work with don't quite fit within the confines of our UIImageViews. In most cases we can use

Beau Nouvelle 3k Jan 3, 2023
Async image downloader with Mem&Disk cached as a UIImageView extension

HBWebImage Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation HBWebIm

haoboxuxu 1 Oct 22, 2022
A UIImageView extension to let the picture-cutting with faces showing better

UIImageView-BetterFace A UIImageView extension to let the picture-cutting with faces showing better Last update in v0.2_stable : add a UIImage+BetterF

Croath Liu 779 Sep 1, 2022
Asynchronous image downloader with cache support as a UIImageView category

This library provides an async image downloader with cache support. For convenience, we added categories for UI elements like UIImageView, UIButton, M

null 24.4k Jan 5, 2023
An image download extension of the image view written in Swift for iOS, tvOS and macOS.

Moa, an image downloader written in Swift for iOS, tvOS and macOS Moa is an image download library written in Swift. It allows to download and show an

Evgenii Neumerzhitckii 330 Sep 9, 2022
UIImageView BetterFace Swift

UIImageView BetterFace Swift

Croath Liu 470 Sep 9, 2022
iOS Framework that makes it easy to preview images on any UIImageView.

AZImagePreview iOS Framework that makes it easy to preview images on any UIImageView. Screenshots Installation: Cocoa Pods: pod 'AZImagePreview' Swift

Antonio Zaitoun 25 Dec 11, 2022
Live rendering of UIImageView properties in Interface Builder

TJProfileImage Live rendering of componet’s properties in Interface Builder Features Dashed border Solid border Round corner Circle image Requirements

Tejas Ardeshna 32 Feb 28, 2022
Media view which subclasses UIImageView, and can display & load images, videos, GIFs, and audio and from the web, and has functionality to minimize from fullscreen, as well as show GIF previews for videos.

I've built out the Swift version of this library! Screenshots Description ABMediaView can display images, videos, as well as now GIFs and Audio! It su

Andrew Boryk 80 Dec 20, 2022
📷 A composable image editor using Core Image and Metal.

Brightroom - Composable image editor - building your own UI Classic Image Editor PhotosCrop Face detection Masking component ?? v2.0.0-alpha now open!

Muukii 2.8k Jan 3, 2023
📷 A composable image editor using Core Image and Metal.

Brightroom - Composable image editor - building your own UI Classic Image Editor PhotosCrop Face detection Masking component ?? v2.0.0-alpha now open!

Muukii 2.8k Jan 2, 2023
SwiftColorArt is a demo application that includes Swift files with all classes and extension necessary to create a font color schema matching to an image

SwiftColorArt SwiftColorArt is a demo application that includes Swift files with all classes and extension necessary to create a font color schema mat

Jan Gregor Triebel 264 Jan 4, 2023
An NSFW image detector for Swift built as an extension on UIImage.

Swift_NSFW_Detector An NSFW image detector for Swift built as an extension on UIImage. If you've ever allowed users to share images you are probably w

Chris Brown 5 Nov 27, 2022
Siri Shortcuts extension for calculating NN-based image hash.

NNHash Siri Shortcuts extension for calculating NN-based image hash. Based on nhcalc.

Yi Xie 3 Aug 9, 2021
AsyncImage before iOS 15. Lightweight, pure SwiftUI Image view, that displays an image downloaded from URL, with auxiliary views and local cache.

URLImage URLImage is a SwiftUI view that displays an image downloaded from provided URL. URLImage manages downloading remote image and caching it loca

Dmytro Anokhin 1k Jan 4, 2023
A complete Mac App: drag an image file to the top section and the bottom section will show you the text of any QRCodes in the image.

QRDecode A complete Mac App: drag an image file to the top section and the bottom section will show you the text of any QRCodes in the image. QRDecode

David Phillip Oster 2 Oct 28, 2022
Convert the image to hexadecimal to send the image to e-paper

ConvertImageToHex Convert the image to hexadecimal to send the image to e-paper Conversion Order // 0. hex로 변환할 이미지 var image = UIImage(named: "sample

Hankyeol Park 0 Feb 26, 2022
Twitter Image Pipeline is a robust and performant image loading and caching framework for iOS clients

Twitter Image Pipeline (a.k.a. TIP) Background The Twitter Image Pipeline is a streamlined framework for fetching and storing images in an application

Twitter 1.8k Dec 17, 2022
Image-cropper - Image cropper for iOS

Image-cropper Example To run the example project, clone the repo, and run pod in

Song Vuthy 0 Jan 6, 2022