效果图:

操作

先github下载<YYText>文件导入,

代码如下:

#import "ViewController.h"
#import "YYLabel.h"
#import "NSAttributedString+YYText.h"
#import <UIKit/UIKit.h> @interface ViewController () @property (nonatomic,strong) YYLabel *label;; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; NSMutableAttributedString *text = [NSMutableAttributedString new];
UIFont *font = [UIFont systemFontOfSize:]; // 添加文本
NSString *title = @"dwwdqwddqdqdqdqwdqdqwdqwdqdqdqdqwdqwdqdqdqwdqdqwdqdqdqdqdqdqwdq当前的群无多群无多群无多群无多群无多群多群无多群无多群无多群无多群多群多群多群当前的群无多群多群无多群多群多群多群多群多群多群多群的权威的权威的期望多无群多群无多群多群多群多群无多群无多群无多群无多群无多群无多群多群无多群无多群多群无多群多群无多无多无群多多群无多群多群多群多群无多群多无!"; [text appendAttributedString:[[NSAttributedString alloc] initWithString:title attributes:nil]]; text.yy_font = font ;
_label = [YYLabel new];
_label.userInteractionEnabled = YES;
_label.numberOfLines = ;
_label.textVerticalAlignment = YYTextVerticalAlignmentTop;
_label.frame = CGRectMake(,, self.view.frame.size.width-,);
_label.attributedText = text;
[self.view addSubview:_label]; _label.layer.borderWidth = 0.5;
_label.layer.borderColor = [UIColor colorWithRed:0.000 green:0.463 blue:1.000 alpha:1.000].CGColor; // 添加全文
[self addSeeMoreButton];
} #pragma mark - 添加全文
- (void)addSeeMoreButton { __weak __typeof(self) weakSelf = self; NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"...全文"]; YYTextHighlight *hi = [YYTextHighlight new];
[hi setColor:[UIColor colorWithRed:0.578 green:0.790 blue:1.000 alpha:1.000]]; hi.tapAction = ^(UIView *containerView,NSAttributedString *text,NSRange range, CGRect rect) {
// 点击全文回调
YYLabel *label = weakSelf.label;
[label sizeToFit];
}; [text yy_setColor:[UIColor colorWithRed:0.000 green:0.449 blue:1.000 alpha:1.000] range:[text.string rangeOfString:@"全文"]];
[text yy_setTextHighlight:hi range:[text.string rangeOfString:@"全文"]];
text.yy_font = _label.font; YYLabel *seeMore = [YYLabel new];
seeMore.attributedText = text;
[seeMore sizeToFit]; NSAttributedString *truncationToken = [NSAttributedString yy_attachmentStringWithContent:seeMore contentMode:UIViewContentModeCenter attachmentSize:seeMore.frame.size alignToFont:text.yy_font alignment:YYTextVerticalAlignmentCenter]; _label.truncationToken = truncationToken;
}

展开label,利用YYText实现文字显示不完末尾添加全文的更多相关文章

  1. Qt添加窗口背景图片、Label图片显示、、Label文字显示

    一.添加窗口背景图片 重写MainWindow绘制事件 void MainWindow::paintEvent(QPaintEvent *event) { QPainter painter(this) ...

  2. Android(java)学习笔记139:在TextView组件中利用Html插入文字或图片

    首先我们看看代码: 1.activity_main.xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/r ...

  3. [置顶] echarts x轴文字显示不全(xAxis文字倾斜比较全面的3种做法值得推荐)

    echarts x轴标签文字过多导致显示不全 如图: 解决办法1:xAxis.axisLabel 属性 axisLabel的类型是object ,主要作用是:坐标轴刻度标签的相关设置.(当然yAxis ...

  4. CSS控制文字显示一行,超出显示省略号

    这几天在项目需求里面遇到了很多之前没做过的需求,也慢慢更加认识到了css的强大,是真的强大.以后会把自己技术调研的东西都写出来,哪怕只是一点点或者很小的点,重在学习. “CSS控制文字显示一行,超出显 ...

  5. echarts x轴文字显示不全(解决方案)

    echarts x轴标签文字过多导致显示不全 如图: 解决办法1:xAxis.axisLabel 属性 axisLabel的类型是object ,主要作用是:坐标轴刻度标签的相关设置.(当然yAxis ...

  6. Android(java)学习笔记81:在TextView组件中利用Html插入文字或图片

    1. TextView中利用Html插入文字或者图片: 首先我们看看代码: (1)activity_main.xml: <LinearLayout xmlns:android="htt ...

  7. Cell 动态行高文字显示不全问题探索

    目录 问题概述 一.新建工程 二.尝试复现问题 尝试解决 修改contentLblBtmCon优先级为High(750) 修改contentLblBtmCon优先级为Low(250) 小结 其他解决思 ...

  8. php 两段文本对比,不同的文字显示高亮

    php 两段文本对比,不同的文字显示高亮[下面这个只能区分错误后面的..]   <?php $str1 ="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwgg ...

  9. 完美解决 向UILable 文字最后插入N张图片,支持向限制行数的UILable 最后一行插入,多余文字显示...

    效果: ====直接上代码吧=== // // UILabel+StringFrame.h // QYER // // Created by qyer on 15/3/19. // Copyright ...

随机推荐

  1. CCSUOJ评测系统——第三次scrum冲刺

    1.小组成员 舒 溢 许嘉荣 唐 浩 黄欣欣 廖帅元 刘洋江 薛思汝 2.个人在小组第三次冲刺的任务及其完成情况描述. 本人在小组第三次冲刺的任务是负责代码的编写,其他人提需求和改进,代码是采用Git ...

  2. LeetCode题解之To Lower Case

    1.题目描述 2.分析 遍历字符串,使用C++ 的 标准库函数 isalpha() 判断字符是否为 字母,然后对其做 tolower() . 3.代码 string toLowerCase(strin ...

  3. c# 设计模式 之:策略模式

    算法与对象的耦合:     对象可能经常需要使用多种不同的算法,但是如果变化频繁,会将类型变得脆弱...             动机:     在软件构建过程中,某些对象使用的算法可能多种多样,经常 ...

  4. ARM CPU 架构

    1978年12月5日,物理学家赫尔曼·豪泽(Hermann Hauser)和工程师Chris Curry,在英国剑桥创办了CPU公司(Cambridge Processing Unit),主要业务是为 ...

  5. scrapy实战--爬取最新美剧

    现在写一个利用scrapy爬虫框架爬取最新美剧的项目. 准备工作: 目标地址:http://www.meijutt.com/new100.html 爬取项目:美剧名称.状态.电视台.更新时间 1.创建 ...

  6. 转:动态table分页(ORCALE)

    前端:<table style="width: 100%;"> <tr> <td> 搜索字: <asp:TextBox ID=" ...

  7. 引用js文件

    在子模板里引用js文件的时候,需要把相应的.js文件放到static目录下,如引用static/jQuery/index.js文件: {% extends "base.html" ...

  8. word 排版用到双直线、波浪线、虚线 、直线、隔行线等技巧

    在办公或毕业设计时,有时排版需要插入双直线.波浪线.虚线 .直线.隔行线等而烦恼, 今天小白与大家分享技巧如下: 感谢您的阅读,如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮.本文欢迎各位转载,但 ...

  9. Celery学习---Celery 分布式队列介绍及安装

    Celery介绍和基本使用 Celery 是一个 基于python开发的分布式异步消息任务队列,通过它可以轻松的实现任务的异步处理, 如果你的业务场景中需要用到异步任务,就可以考虑使用celery, ...

  10. 解决windows10下无法安装.net framework 3.5,错误代码0x800F081F

    1.下载 NET Framework 3.5的安装包netfx3.cab: http://download.windowsupdate.com/d/msdownload/update/software ...