之前做過一個(gè)集成環(huán)信的項(xiàng)目,里面涉及到群聊部分揽浙,老大要求是做成微信群聊那種頭像镰官,自己寫了個(gè)demo 模仿微信群聊頭像
使用方法很簡單,把 UIImage+Addtions 這個(gè)類拖到項(xiàng)目中崇渗,在需要顯示的地方調(diào)用:
1.加載網(wǎng)絡(luò)圖片使用此方法
NSURL *icon1URL = [NSURL URLWithString:@"http://upload-images.jianshu.io/upload_images/3816723-e182f6da029b3e7d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/100"] ;
NSURL *icon2URL = [NSURL URLWithString:@"http://upload-images.jianshu.io/upload_images/3816723-023e66be11a2e94b.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/100"];
NSURL *icon3URL = [NSURL URLWithString:@"http://upload-images.jianshu.io/upload_images/3816723-d7ece9dba73d4953.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/100"] ;
NSURL *icon4URL = [NSURL URLWithString:@"http://upload-images.jianshu.io/upload_images/3816723-e08bf975aadbfdd4.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/100"] ;
NSURL *icon5URL = [NSURL URLWithString:@"http://upload-images.jianshu.io/upload_images/3816723-13271b280c0e5fd4.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/100"] ;
NSArray *iconItemsArr = @[icon1URL,icon2URL,icon3URL,icon4URL,icon5URL];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(150, 150, 100, 100)];
imageView.image = [UIImage groupIconWithURLArray:iconItemsArr bgColor:[UIColor groupTableViewBackgroundColor]];
[self.view addSubview:imageView];
2.加載本地圖片使用(一般用不到加載本地的圖片):
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
imageView.image = [UIImage groupIconWith:@[@"user.png", @"user1.jpg", @"user2.jpg", @"user.png", @"user1.jpg", @"user.png", @"user1.jpg", @"user1.jpg", @"user1.jpg", @"user1.jpg"] bgColor:[UIColor groupTableViewBackgroundColor]];
[self.view addSubview:imageView];
3.效果圖:
效果圖
4.最后說一點(diǎn),這是手機(jī)端進(jìn)行得到icon操作京郑,不可能每次加載都走這樣的流程宅广,影響APP性能,所以些举,比較合理的方法是:創(chuàng)建群組的時(shí)候跟狱,把通過這種方式得到的image上傳到服務(wù)器,當(dāng)我們獲取群組信息時(shí)户魏,服務(wù)器返回url驶臊,以后每次都通過url加載。