//
// EmotionView.m
// WXWeibo
//
// Created by apple on 14-6-3.
// Copyright (c) 2014年 com.tyust. All rights reserved.
//
#import "EmotionView.h"
#define item_weidth 42
#define item_height 45
@implementation EmotionView
{
NSMutableArray *pages;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self _init];
self.backgroundColor = [UIColor clearColor];
}
return self;
}
-(void)_init
{
NSString *emotionPlistPath = [[NSBundle mainBundle]pathForResource:@"emoticons" ofType:@"plist"];
NSArray *array = [[NSArray alloc]initWithContentsOfFile:emotionPlistPath];
int pageCout = array.count/28;
pages = [[NSMutableArray alloc]initWithCapacity:pageCout];
NSMutableArray *emotions = nil;
for(int i = 0;i<array.count;i++)
{
if(i%28==0)
{
emotions = [[NSMutableArray alloc]initWithCapacity:28];
[pages addObject:emotions];
}
[emotions addObject:array[i]];
}
NSLog(@"pageCout--> %d",pageCout);
self.width = (pageCout+1) * 320;
self.height = 4 * item_height;
}
-(void)drawRect:(CGRect)rect
{
int colum = 0,row=0;
for(int i=0;i<pages.count;i++)
{
NSMutableArray *emotions = pages[i];
for(int j = 0;j<emotions.count;j++)
{
colum++;
NSDictionary *dic = emotions[j];
NSString *imgName = [dic objectForKey:@"png"];
UIImage *img = [UIImage imageNamed:imgName];
CGRect rect = CGRectMake(colum * item_weidth + i * 320 - 20 ,row * item_height + 15,30,30);
[img drawInRect:rect];
if(colum%7==0)
{
row++;
colum=0;
}
if(row%4==0)
{
row=0;
}
}
}
}
@end
IOS--表情粗显示
最新推荐文章于 2024-12-09 18:47:03 发布