在Xcode中,我尝试在我的自定义键盘上添加一些表情符号。我想用一个图像作为表情符号。
由于我不知道如何将图像转换为表情符号,因此我无法创建在消息传递中发送按钮图像的按钮。如何创建一个按钮,在消息传递中发送按钮的图像?
我曾尝试将图片转换为NSdata,但尝试失败了。
这是我的一些代码
-(void) addGestureToKeyboard{
[self.keyboard.deleteKey addTarget:self action:@selector(pressDeleteKey)
forControlEvents:UIControlEventTouchUpInside];
[self.keyboard.enterKey addTarget:self action:@selector(pressEnterKey)
forControlEvents:UIControlEventTouchUpInside];
[self.keyboard.nextKey addTarget:self action:@selector(advanceToNextInputMode)
forControlEvents:UIControlEventTouchUpInside];
[self.keyboard.smileyKey addTarget:self action:@selector(pressSmileyKey:)
forControlEvents:UIControlEventTouchUpInside];
for (UIButton * keys in self.keyboard.keysArray) {
[keys addTarget:self action:@ selector(pressKey:)
forControlEvents:UIControlEventTouchUpInside];
}
}
-(void) pressDeleteKey{
[self.textDocumentProxy deleteBackward];
}
-(void) pressEnterKey{
[self.textDocumentProxy insertText:@"\n"];
}
-(void) pressKey:(UIButton *) key{
[self.textDocumentProxy insertText:[key currentTitle]];
}
-(void) pressSmileyKey:(UIButton *) skey{
NSData *imageData= UIImageJPEGRepresentation([skey currentImage], 1.0);
[self.textDocumentProxy insertText: imageData];
}