UIImageView-AGCInitials 0.0.2

UIImageView-AGCInitials 0.0.2

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Apr 2016

Maintained by Andrea Cipriani.




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+

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.