新浪微博客户端(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()方法 ...
随机推荐
- 77.Android之代码混淆
转载:http://www.jianshu.com/p/7436a1a32891 简介 作为Android开发者,如果你不想开源你的应用,那么在应用发布前,就需要对代码进行混淆处理,从而让我们代码即使 ...
- Linux下的IO模式
对于一次IO访问(以read举例),数据会先被拷贝到操作系统内核的缓冲区中,然后才会从操作系统内核的缓冲区拷贝到应用程序的地址空间.所以说,当一个read操作发生时,它会经历两个阶段:1. 等待数据准 ...
- SVN分支研究
在结合之前总结的定制开发的产品版本开发问题解决的方法:http://www.cnblogs.com/EasonJim/p/5971906.html,今天来研究以下用SVN处理这类的问题. 研究SVN分 ...
- 利用TabHost制作QQ客户端标签栏效果(低版本QQ)
学习一定要从基础学起,只有有一个好的基础,我们才会变得更加的perfect 下面小编将利用TabHost制作QQ客户端标签栏效果(这个版本的QQ是在前几年发布的)…. 首先我们看一下效果: 看到这个界 ...
- ecshop /pick_out.php SQL Injection Vul By Local Variable Overriding
catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 在进行输入变量本地模拟注册的时候,没有进行有效的GPC模拟过滤处理,导出 ...
- JS 复制对象
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs& ...
- python使用cookielib库示例分享
Python中cookielib库(python3中为http.cookiejar)为存储和管理cookie提供客户端支持,下面是使用示例 该模块主要功能是提供可存储cookie的对象.使用此模块捕获 ...
- Objective -C学习笔记 之copy(复制)
//自定义类对象实现copy需要遵守copy协议(否则程序崩溃),实现必须实现的协议方法,里面的代码就决定了你的copy是深是浅 #import <Foundation/Foundation.h ...
- ADS1.2安装教程
工具/原料 ADS1.2 ADS1.2安装教程 1 在安装包内找到”Setup“,点击安装. 点击”Next“.然后进入License Agreement ,点击”Yes“. 点击了Yes之后,我们选 ...
- WinForm------Reflector反编译工具下载
地址: http://www.ddooo.com/softdown/70642.htm