UIImageView-Letters

https://github.com/bachonk/UIImageView-Letters

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

一个简单,易用的,根据用户的英文名字生成了一个placeholder文件,并随机赋上一种颜色

Usage

In the file where you want to use the category, be sure to import the file.

#import "UIImageView+Letters.h"

在你想用的地方,引入头文件即可

Methods 方法

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

你可以给UIImageView调用如下两种方法:

  • - (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.

string是用来产生缩写的,当然,这个得需要是用户合法的全名。

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

颜色是备选参数,用来设置图片背景色的。如果你传递了nil值,他会给你随机产生一种颜色。

Example 使用示例

NSString *userName = @"Michael Bluth";
UIImageView *myImgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
[myImgView setImageWithString:userName];

以下附上本人的使用教程:

//
// RootViewController.m
// Letter
//
// Created by YouXianMing on 14-9-13.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import "RootViewController.h"
#import "UIImageView+Letters.h" @interface RootViewController () @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad]; NSArray *nameArray = @[@"Michael Bluth", @"You Xian", @"Jim Simith",
@"Li Dian", @"Jun Gang", @"You Jin",
@"Lin Ken", @"Li kui", @"Leter Jun"]; for (int i = ; i < nameArray.count; i++)
{
NSString *userName = nameArray[i];
UIImageView *myImgView = \
[[UIImageView alloc] initWithFrame:CGRectMake( + (i%)*, // 求余
+ (i/)*, // 取整
, )];
myImgView.layer.cornerRadius = .f;
myImgView.layer.masksToBounds = YES;
[myImgView setImageWithString:userName];
[self.view addSubview:myImgView];
}
} @end

再来看看人家的源码:

[翻译] UIImageView-Letters的更多相关文章

  1. [翻译]AKKA笔记 -ACTOR SUPERVISION - 8

    失败更像是分布式系统的一个特性.因此Akka用一个容忍失败的模型,在你的业务逻辑与失败处理逻辑(supervision逻辑)中间你能有一个清晰的边界.只需要一点点工作,这很赞.这就是我们要讨论的主题. ...

  2. StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing the strings?

    StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing t ...

  3. (翻译)开始iOS 7中自动布局教程(二)

    这篇教程的前半部分被翻译出来很久了,我也是通过这个教程学会的IOS自动布局.但是后半部分(即本篇)一直未有翻译,正好最近跳坑翻译,就寻来这篇教程,进行翻译.前半部分已经转载至本博客,后半部分即本篇.学 ...

  4. 《Entity Framework 6 Recipes》中文翻译系列 (30) ------ 第六章 继承与建模高级应用之多对多关联

    翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 第六章  继承与建模高级应用 现在,你应该对实体框架中基本的建模有了一定的了解,本章 ...

  5. poj 2503:Babelfish(字典树,经典题,字典翻译)

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30816   Accepted: 13283 Descr ...

  6. AFNetworking2.0 NSHipster翻译

    AFNetworking 是当前 iOS 和 Mac OS X 开发中最广泛使用的开源项目之一.它帮助了成千上万叫好又叫座的应用,也为其它出色的开源库提供了基础.这个项目是社区里最活跃.最有影响力的项 ...

  7. PEP8中文翻译(转)

    原文:https://github.com/zgia/manual PEP 8 -- Style Guide for Python Code PEP Index > PEP 8 -- Style ...

  8. face recognition[翻译][深度人脸识别:综述]

    这里翻译下<Deep face recognition: a survey v4>. 1 引言 由于它的非侵入性和自然特征,人脸识别已经成为身份识别中重要的生物认证技术,也已经应用到许多领 ...

  9. UnicodeMath数学公式编码_翻译(Unicode Nearly Plain - Text Encoding of Mathematics Version 3)

    目录 完整目录 1. 简介 2. 编码简单数学表达式 2.1 分数 2.2 上标和下标 2.3 空白(空格)字符使用 3. 编码其他数学表达式 3.1 分隔符 强烈推荐本文简明版UnicodeMath ...

随机推荐

  1. Python2.x 中文乱码问题

    Python 文件中如果未指定编码,在执行过程会出现报错: #!/usr/bin/pythonprint "你好,世界"; 以上程序执行输出结果为: File "test ...

  2. SpringMVC源码阅读:Json,Xml自动转换

    1.前言 SpringMVC是目前J2EE平台的主流Web框架,不熟悉的园友可以看SpringMVC源码阅读入门,它交代了SpringMVC的基础知识和源码阅读的技巧 本文将通过源码(基于Spring ...

  3. UOJ #356. 【JOI2017春季合宿】Port Facility

    Description 小M有两个本质不同的栈. 无聊的小M找来了n个玩具.之后小M把这n个玩具随机顺序加入某一个栈或把他们弹出. 现在小M告诉你每个玩具的入栈和出栈时间,现在她想考考小S,有多少种方 ...

  4. [转]微信小程序之加载更多(分页加载)实例 —— 微信小程序实战系列(2)

    本文转自;http://blog.csdn.net/michael_ouyang/article/details/56846185 loadmore 加载更多(分页加载) 当用户打开一个页面时,假设后 ...

  5. DedeCMS修改管理员用户名

    织梦内容管理系统(DedeCMS) 以简单.实用.开源而闻名,是国内最知名的PHP开源网站管理系统,也是使用用户最多的PHP类CMS系统,在经历多年的发展,目前的版本无论在功能,还是在易用性方面,都有 ...

  6. 我用ASP.NET缓存之数据缓存

    [我的理解] Cache,是内置的对象集合.是全局的,类似于static Arraylist.它是线程安全的,添加或修改Cache中的项目时,不需要锁定或者解除Cache. 添加 Cache[Key] ...

  7. Java基础教程(10)--类

    一.声明类   你已经见过了以如下方式定义的类: class MyClass { // field, constructor, and method declarations }   上面是声明类的最 ...

  8. 地址解析协议ARP,网络层协议IP、ICMP协议

    分析所用软件下载:Wireshark-win32-1.10.2.exe 阅读导览 1. 分析并且应用ARP协议 2.分析IP协议 3.分析ICMP协议 1.分析arp报文的格式与内容 (1)ping ...

  9. 深入理解MyBatis的原理(三):配置文件用法(续)

    前言:前文讲解了 MyBatis 的配置文件一部分用法,本文将继续讲解 MyBatis 的配置文件的用法. 目录 1.typeHandler 类型处理器 2.ObjectFactory 3.插件 4. ...

  10. PHP的new self() 与new static()

    参考链接:[PHP中new static()与new self()的区别异同分析],[PHP中new self()和new static()的区别探究],[PHP中static和self的区别] 要点 ...