An easy, helpful UIImageView category that generates letter initials as a placeholder for user profile images, with a randomized background color
Add this spec to your podfile:
pod "UIImageView-Letters"
Check out the official guide for getting started with CocoaPods.
- Drag the
UIImageView+Letters.{h,m}
files into your project - Enjoy!
In the file where you want to use the category, be sure to import the file.
#import "UIImageView+Letters.h"
Call the following methods on any UIImageView
instance to set the image:
- (void)setImageWithString:(NSString *)string
- (void)setImageWithString:(NSString *)string color:(UIColor *)color
string
is the string used to generate the initials. This should be a user's full name if available.
color
is an optional parameter that sets the background color of the image. Pass in nil
to have a color automatically generated for you.
NSString *userName = @"Michael Bluth";
UIImageView *myImgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
[myImgView setImageWithString:userName];
If you like this tool, show your support by downloading the free Reach Contact List app that inspired it!
Using the MIT license. See license file for details.