新浪微博客户端(50)-解决输入Emotion表情逐渐变小的问题
UITextView+Extension.h
- #import <UIKit/UIKit.h>
- @interface UITextView (Extension)
- /** 插入属性文本 */
- - (NSMutableAttributedString *)insertAttributeText:(NSAttributedString *)insertAttrText;
- /** 插入属性文本和要设置的block内容 */
- - (NSMutableAttributedString *)insertAttributeText:(NSAttributedString *)insertAttrText settingsBlock:(void (^)(NSMutableAttributedString * attributedString)) settingsBlock;
- @end
UITextView+Extension.m
- #import "UITextView+Extension.h"
- @implementation UITextView (Extension)
- - (NSMutableAttributedString *)insertAttributeText:(NSAttributedString *)insertAttrText {
- return [self insertAttributeText:insertAttrText settingsBlock:nil];
- }
- - (NSMutableAttributedString *)insertAttributeText:(NSAttributedString *)insertAttrText settingsBlock:(void (^)(NSMutableAttributedString *))settingsBlock {
- // 以textView的原本内容为基础构造一个attrStr
- NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithAttributedString:self.attributedText];
- // 将附件文本插入到光标所在的位置
- NSUInteger cursorLocation = self.selectedRange.location;
- [attrStr insertAttributedString:insertAttrText atIndex:cursorLocation];
- // 如果传入了block,就调用block
- if(settingsBlock) {
- settingsBlock(attrStr);
- }
- // 更新当前textView内容
- self.attributedText = attrStr;
- // 修正当前光标位置(将光标移动到插入表情末尾,默认光标会跳转到所有文本最后)
- self.selectedRange = NSMakeRange(cursorLocation + , );
- return attrStr;
- }
- @end
DJEmotionTextView.m
- #import "DJEmotionTextView.h"
- #import "DJEmotion.h"
- @implementation DJEmotionTextView
- - (void)insertEmotion:(DJEmotion *)emotion {
- // 插入表情
- if (emotion.code) { // Emoji表情
- [self insertText:[NSString emojiWithStringCode:emotion.code]];
- } else if (emotion.png) { // 表情图片
- NSString *emotionName = emotion.png;
- NSString *imagePath;
- if ([emotionName hasPrefix:@"d_"] || [emotionName hasPrefix:@"f_"] ||
- [emotionName hasPrefix:@"h_"] || [emotionName hasPrefix:@"l_"] || [emotionName hasPrefix:@"o_"] || [emotionName hasPrefix:@"w_"]) {
- imagePath = [NSString stringWithFormat:@"EmotionIcons/default/%@",emotion.png]; // 默认表情路径
- } else if ([emotionName hasPrefix:@"lxh_"]) {
- imagePath = [NSString stringWithFormat:@"EmotionIcons/lxh/%@",emotion.png]; // 浪小花表情路径
- }
- // 构造表情附件
- NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
- attachment.image = [UIImage imageNamed:imagePath];
- CGFloat attachmentWH = self.font.lineHeight;
- attachment.bounds = CGRectMake(, -, attachmentWH, attachmentWH);
- NSAttributedString *attachStr = [NSAttributedString attributedStringWithAttachment:attachment];
- // 插入属性文本
- [self insertAttributeText:attachStr settingsBlock:^(NSMutableAttributedString *attributedString) {
- // 设置当前attrStr的字体与textView原有字体大小一致,因为attrStr的字体无法通过textview.font属性来设置
- [attributedString addAttribute:NSFontAttributeName value:self.font range:NSMakeRange(, attributedString.length)];
- }];
- }
- }
- @end
新浪微博客户端(50)-解决输入Emotion表情逐渐变小的问题的更多相关文章
- vue-cli3.0结合lib-flexible、px2rem实现移动端适配,完美解决第三方ui库样式变小问题
公司最近做的一个移动端项目从搭框架到前端开发由我独立完成,以前做移动端适配用的媒体查询,这次想用点别的适配方案,然后就采用了vue-cli3.0结合lib-flexible.px2rem实现移动端适配 ...
- 新浪微博客户端(49)-删除输入的Emotion表情
DJComposePageView.m - (void)deleteInputEmotion { // 发通知 [[NSNotificationCenter defaultCenter] postNo ...
- android 新浪微博客户端的表情功能的实现
这是一篇好文章,我转来收藏,技术的最高境界是分享. 最近在搞android 新浪微博客户端,有一些心得分享弄android客户端表情功能可以用以下思路1.首页把新浪的表情下载到本地一文件夹种,表情图片 ...
- android开发新浪微博客户端 完整攻略 [新手必读]
开始接触学习android已经有3个礼拜了,一直都是对着android的sdk文档写Tutorials从Hello World到Notepad Tutorial算是初步入门了吧,刚好最近对微博感兴趣就 ...
- Android 聊天表情输入、表情翻页带效果、下拉刷新聊天记录
经过一个星期的折腾,最终做完了这个Android 聊天表情输入.表情翻页带效果.下拉刷新聊天记录.这仅仅是一个单独聊天表情的输入,以及聊天的效果实现.由于我没有写server,所以没有两方聊天的效果. ...
- Aisen仿新浪微博客户端项目源码
新浪目前已经限制了第三方微博的很多API接口,加上平常时间不够,所以后续可能不会面向产品的去维护Aisen,不过也有了一些新的方向,例如引入最新Android-support-library,在一个完 ...
- Android应用--新浪微博客户端新特性滚动视图和启动界面实现
新浪微博客户端新特性滚动视图和启动界面实现 2013年8月20日新浪微博客户端开发之启动界面实现 前言: 使用过新浪微博客户端的童鞋都清楚,客户端每一次升级之后第一次启动界面就会有新特性的介绍,用户通 ...
- 新浪微博客户端开发之OAuth认证篇
新浪微博客户端开发之OAuth认证篇 2013年7月29日新浪微博客户端开发 OAuth2.0授权机制我在这里就不浪费口舌了,有很多大牛都发表过相关的文章解释OAuth2.0认证的流程,我就随便找了一 ...
- tcp程序设计--客户端获取服务器输入输出流
tcp程序设计--客户端获取服务器输入输出流 思路: 第一步:实例化一个ServerSocket对象(服务器套接字),用来等待网络上的请求(也就是等待来连接的套接字) 第二步:调用accept()方法 ...
随机推荐
- iOS极光推送 点击推送消息跳转页面
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...
- 【BZOJ-2503】相框 并查集 + 分类讨论
2503: 相框 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 71 Solved: 31[Submit][Status][Discuss] Desc ...
- BZOJ1912 [Apio2010]patrol 巡逻
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...
- ES5/ES6的区别研究(ECMAScript)
我所理解的概念应该是语法的区别和特性的区别 这里是ECMAScript的解析http://baike.baidu.com/item/ECMAScript 参考: (ES6)http://es6.rua ...
- Ubuntu下root密码认证错误
1.默认root密码是随机的,即每次开机都有一个新的root密码.我们可以在终端输入命令 sudo passwd root,然后输入当前用户的密码,再输入要设置root的密码,我们一般设置成两个都一样 ...
- Andorid视觉新冲击-Material design语言
[写在前面] google在2014年 I/O大会上推出了一种新的设计设计语言—Material design,这种设计语言语言旨在为手机.平板电脑.台式机和“其他平台”提供更一致.更广泛的“外观和感 ...
- Bzoj1189 [HNOI2007]紧急疏散evacuate
1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2293 Solved: 715 Descr ...
- [NOIP2013] 提高组 洛谷P1969 积木大赛
题目描述 春春幼儿园举办了一年一度的“积木大赛”.今年比赛的内容是搭建一座宽度为n的大厦,大厦可以看成由n块宽度为1的积木组成,第i块积木的最终高度需要是hi. 在搭建开始之前,没有任何积木(可以看成 ...
- c/c++中#和##链接符号的用法
#include <stdio.h> #include <stdlib.h> /* 英语原文: In function-like macros, a # operator be ...
- 使用enum建立简单的状态机
Overview The enum in Java is more powerful than many other languages which can lead to surprising us ...