弹出视图,可以从 iOS 6+ 的可能字符中选择表情符号字符。iOS 6+, ARC。
请复制项目后运行
// download Popover submodule(s)
git submodule init
git submodule update
它包括两个类:
SYEmojiPopover
SYEmojiCharacters
SYEmojiCharacters
根据手机运行的 iOS 版本生成表情符号字符列表,分节显示。我使用了 iOS Emji 键盘来在文件 Characters/characters.txt
中列出这些字符。它包含从 5.0 开始显示在 iOS 键盘上的表情符号字符,以及操作系统即使不在键盘上也支持的字符。
它包含以下方法:
// singleton for this class
+(SYEmojiCharacters*)sharedCharacters;
// determines if a string is an Emoji character supported in this iOS version
-(BOOL)isCharacterEmoji:(NSString *)string;
// number of sections of characters
-(NSUInteger)numberOfSections;
// number of characters in the section
-(NSUInteger)numberOfRowsInSection:(NSUInteger)section;
// character in given section at given index
-(NSString*)emojiAtRow:(NSUInteger)row andSection:(NSUInteger)section;
第二个类,SYEmojiPopover
,是弹出视图。弹出视图本身由 NicolasChengDev 制作,可以在这里找到:[WYPopoverController](https://github.com/nicolaschengdev/WYPopoverController)。弹出视图中的视图使用 UITableView 实现。它比在前版本中可能找到的 GMGridView
快得多,但更改控件大小的能力稍微困难一些,这就是为什么它还没有被实现的原因。
以下是可以使用的方法:
// delegate
@property (weak, atomic) id<SYEmojiPopoverDelegate> delegate;
// show the control at the specified point of a view, using a title
-(void)showFromPoint:(CGPoint)point inView:(UIView*)view withTitle:(NSString*)title;
代理属性实现了 SYEmojiPopoverDelegate
,包括以下方法:
// required, will be called when a character is tapped
-(void)emojiPopover:(SYEmojiPopover*)emojiPopover didClickedOnCharacter:(NSString*)character;
提供了一个示例项目,它是与源代码一起提供的。该项目显示弹出视图并在点击后显示字符。
弹出视图的实例是主视图控制器的一个私有成员
@interface SYViewController : UIViewController <SYEmojiPopoverDelegate> {
@private
SYEmojiPopover *_emojiPopover;
}
点击按钮时
- (IBAction)selectEmojiClick:(id)sender {
if(!self->_emojiPopover)
self->_emojiPopover = [[SYEmojiPopover alloc] init];
[self->_emojiPopover setDelegate:self];
[self->_emojiPopover showFromPoint:self.buttonEmoji.center
inView:self.view
withTitle:@"Click on a character to see it in big"];
}
点击表情符号字符时调用该方法
-(void)emojiPopover:(SYEmojiPopover *)emojiPopover didClickedOnCharacter:(NSString *)character
{
[self.labelEmoji setFont:[UIFont fontWithName:@"AppleColorEmoji" size:100.f]];
[self.labelEmoji setText:character];
}
存储库还包含一个简单的 OSX 应用。其目标是使用文本文件(我的文件是 Characters/characters.txt
)创建 SYEmojiCharacters
的 -(void)loadCharacters
方法。
文本文件使用自定义结构,请谨慎使用以确保应用能正常运行。
我将它包含在内,以便与该项目一起保存在同一存储库中,但它仅对希望添加字符或以不同方式组织部分的您有用。
任何类型的贡献都热烈欢迎,所以如果您有任何问题、建议或错误报告,请不要犹豫,在 Github 上联系我,我很乐意回答您。
如果您的应用正在使用此代码,请与我联系,以便我将它添加到供人们查看此项目的应用程序列表中。
我对许可证不太了解,所以不会提供一个具体的许可证。我将只指定我认为公平的一些规定。
希望您会喜欢它,
-- dvkch