标签:
//将数字转为
#define EMOJI_CODE_TO_SYMBOL(x) ((((0x808080F0 | (x & 0x3F000) >> 4) | (x & 0xFC0) << 10) | (x & 0x1C0000) << 18) | (x & 0x3F) << 24);
//获取默认表情数组
- (NSArray *)defaultEmoticons {
NSMutableArray *array = [NSMutableArray new];
for (int i=0x1F600; i<=0x1F64F; i++) {
if (i < 0x1F641 || i > 0x1F644) {
int sym = EMOJI_CODE_TO_SYMBOL(i);
NSString *emoT = [[NSString alloc] initWithBytes:&sym length:sizeof(sym)encoding:NSUTF8StringEncoding];
[array addObject:emoT];
}
}
return array;
}
//获取数组
NSArray *arrEmotion = [self defaultEmoticons];
//将表情放到UIButton里
CGFloat W = 30;
CGFloat H = 30;
CGFloat X;
CGFloat Y;
for (int i = 0; i count; i ++) {
X = 10 +(W+5) * (i%10);
Y = 260 + (i/10)* (H +5);
UIButton *biaoqing =[[UIButton alloc] init];
biaoqing.backgroundColor = [UIColor redColor];
biaoqing.frame = CGRectMake(X, Y, W, H);
[self.view addSubview:biaoqing];
NSString *Str = arrEmotion[i];
[biaoqing setTitle:Str forState:UIControlStateNormal];
biaoqing.tag = i;
[biaoqing addTarget:self action:@selector(biaoqingClick:)forControlEvents:UIControlEventTouchUpInside];
}
- (void) biaoqingClick:(UIButton *)biaoqing{
NSArray *emoji = [self defaultEmoticons];
NSString *str = emoji[biaoqing.tag];
self.textField.text = str;
}
标签:
原文地址:http://www.cnblogs.com/Hakim/p/5634025.html