Latest 0.0.2
Homepage https://github.com/AndreaCipriani/UIImageView-AGCInitials
License MIT
Platforms ios 7.0, requires ARC
Authors

CI Status
Version
License
Platform

AGCInitials Example screenshot 1
AGCInitials Example screenshot 2

AGCInitials is an objc UIImageView category to set an image placeholder with the contact’s initials and an automatically generated background color.

Features

  • Use it with one line of code
  • The generated background color of the imageView will be the same for the same initials, so you can use it in your table/collection view. 😎
  • You can set your own color palette for background colors
  • Good test coverage 💪

How to use it – Basic

Import the category

#import "UIImageView+AGCInitials.h"

and then call the method with the contact’s name:

[_anImageView agc_setImageWithInitialsFromName:@"Mick Jagger"];

The image will then contain a placeholder with the initials "MJ" and a generated background color.

Mick Jagger initials example

How to use it – Details

  • You can set the initials directly, without specifying a name, please note that in this case the background color of the image will be the same for the same initials:
- (void)agc_setImageWithInitials:(nonnull NSString*)initials;
  • The initialsFromName method for @"Mick Jagger" and @"Michael Jackson" returns MJ as initials, but the background color will be different, because it’s generated from the name.

Mick Jagger initials example Michael Jackson initials example

  • By default the initials are distinguished by @" ", but you can change the separator using:
- (void)agc_setImageWithInitialsFromName:(nonnull NSString*)name separatedByString:(nonnull NSString*)separator;
  • You can customize the font by specifying the text attributes:
NSDictionary* initialsTextAttributes = @{ NSFontAttributeName : [UIFont systemFontOfSize:20], NSForegroundColorAttributeName : [UIColor purpleColor] };
[cellImageView agc_setImageWithInitialsFromName:@"Mick Jagger" separatedByString:@" " withTextAttributes:initialsTextAttributes];
  • You can also change the color palette used to generate background colors:
#import "AGCInitialsColors.h"

And then just set your palette before using the category:

NSArray<UIColor*>* yourColorPalette; //...
[[AGCInitialsColors sharedInstance] setColorPalette:yourColorPalette];

Requirements

  • iOS 7+

Installation with Cocoapods

UIImageView-AGCInitials is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "UIImageView-AGCInitials"

Installation without Cocoapods

Copy and paste AGCInitialsColors.h/m and UIImageView+AGCInitials.h/m classes into your project.

Run the example

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

You can even try the example online with Appetize

Author

Andrea Cipriani, [email protected] – Twitter @AndreaCipriani

License

UIImageView-AGCInitials is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "UIImageView-AGCInitials",
    "version": "0.0.2",
    "summary": "An UIImageView category to set the initials of a contact's name as the image placeholder",
    "description": "An UIImageView category that allows to set an image containing the initials of a contact's name with a colored background. The color of the background is automatically generated and it is the same for identical names, so you can use it with cell recycle in table/collection view!",
    "homepage": "https://github.com/AndreaCipriani/UIImageView-AGCInitials",
    "screenshots": [
        "https://raw.githubusercontent.com/andreacipriani/UIImageView-AGCInitials/master/Screenshots/agc_screen1.png",
        "https://raw.githubusercontent.com/andreacipriani/UIImageView-AGCInitials/master/Screenshots/agc_screen2.png"
    ],
    "license": "MIT",
    "authors": {
        "Andrea Cipriani": "[email protected]"
    },
    "source": {
        "git": "https://github.com/AndreaCipriani/UIImageView-AGCInitials.git",
        "tag": "0.0.2"
    },
    "social_media_url": "https://twitter.com/AndreaCipriani",
    "platforms": {
        "ios": "7.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*"
}

Pin It on Pinterest

Share This