zoukankan      html  css  js  c++  java
  • [翻译] UIImageView-Letters

    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 = 0; i < nameArray.count; i++)
        {
            NSString     *userName        = nameArray[i];
            UIImageView *myImgView        = 
                [[UIImageView alloc] initWithFrame:CGRectMake(30 + (i%3)*100, // 求余
                                                              30 + (i/3)*100, // 取整
                                                              60, 60)];
            myImgView.layer.cornerRadius  = 30.f;
            myImgView.layer.masksToBounds = YES;
            [myImgView setImageWithString:userName];
            [self.view addSubview:myImgView];
        }
    }
    
    @end

    再来看看人家的源码:

  • 相关阅读:
    排序链表
    给定两个字符串 s 和 t,它们只包含小写字母。 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。 请找出在 t 中被添加的字母。
    给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。
    快速排序之三路快排
    双向链表实现
    删除链表重复元素
    链表是否是回文串
    链表逆序
    排序之归并排序
    线性表之链表实现
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/3970181.html
Copyright © 2011-2022 走看看