UIImageView-Letters 1.1.4

UIImageView-Letters 1.1.4

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布日期上次发布2015年8月

Tom Bachant维护。




  • Tom Bachant

UIImageView+Letters

这是一个易于使用、功能强大的UIImageView分类,它可以生成随机的背景颜色的字母首字母,用作用户头像的占位符。

Example screenshot

安装

手动
  1. UIImageView+Letters.{h,m}文件拖到您的项目中。
  2. 享受吧!

用法

在您想使用该分类的文件中,务必导入该文件。

#import "UIImageView+Letters.h"

方法

可以在任何UIImageView实例上调用以下方法来设置图像:

  • - (void)setImageWithString:(NSString *)string
  • - (void)setImageWithString:(NSString *)string color:(UIColor *)color
  • - (void)setImageWithString:(NSString *)string color:(UIColor *)color circular:(BOOL)isCircular
  • - (void)setImageWithString:(NSString *)string color:(UIColor *)color circular:(BOOL)isCircular fontName:(NSString *)fontName
  • - (void)setImageWithString:(NSString *)string color:(UIColor *)color circular:(BOOL)isCircular textAttributes:(NSDictionary *)textAttributes

string用于生成首字母的字符串。如果可能,应为用户的完整姓名。

color是一个可选参数,用于设置图像的背景颜色。传入nil将自动为您生成颜色。

isCircular是一个布尔参数,如果启用,将自动裁剪图像成圆形。

fontName是一个指定自定义字体的字符串。传入nil将默认使用系统字体。提供的字体标识符列表可以在此处找到。

textAttributes是一个NSDictionary,允许您使用在NSAttributedString.h中找到的键为字母的文本指定字体、文本颜色、阴影属性等。

示例
NSString *userName = @"Michael Bluth";
UIImageView *myImgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
[myImgView setImageWithString:userName color:nil circular:YES];

感谢

如果您喜欢这个工具,请通过下载免费的Reach Contact List应用程序来支持它!

许可证

使用MIT许可证。有关详细信息,请参阅许可证文件。