展开label,利用YYText实现文字显示不完末尾添加全文
效果图:

操作
先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实现文字显示不完末尾添加全文的更多相关文章
- Qt添加窗口背景图片、Label图片显示、、Label文字显示
一.添加窗口背景图片 重写MainWindow绘制事件 void MainWindow::paintEvent(QPaintEvent *event) { QPainter painter(this) ...
- Android(java)学习笔记139:在TextView组件中利用Html插入文字或图片
首先我们看看代码: 1.activity_main.xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/r ...
- [置顶]
echarts x轴文字显示不全(xAxis文字倾斜比较全面的3种做法值得推荐)
echarts x轴标签文字过多导致显示不全 如图: 解决办法1:xAxis.axisLabel 属性 axisLabel的类型是object ,主要作用是:坐标轴刻度标签的相关设置.(当然yAxis ...
- CSS控制文字显示一行,超出显示省略号
这几天在项目需求里面遇到了很多之前没做过的需求,也慢慢更加认识到了css的强大,是真的强大.以后会把自己技术调研的东西都写出来,哪怕只是一点点或者很小的点,重在学习. “CSS控制文字显示一行,超出显 ...
- echarts x轴文字显示不全(解决方案)
echarts x轴标签文字过多导致显示不全 如图: 解决办法1:xAxis.axisLabel 属性 axisLabel的类型是object ,主要作用是:坐标轴刻度标签的相关设置.(当然yAxis ...
- Android(java)学习笔记81:在TextView组件中利用Html插入文字或图片
1. TextView中利用Html插入文字或者图片: 首先我们看看代码: (1)activity_main.xml: <LinearLayout xmlns:android="htt ...
- Cell 动态行高文字显示不全问题探索
目录 问题概述 一.新建工程 二.尝试复现问题 尝试解决 修改contentLblBtmCon优先级为High(750) 修改contentLblBtmCon优先级为Low(250) 小结 其他解决思 ...
- php 两段文本对比,不同的文字显示高亮
php 两段文本对比,不同的文字显示高亮[下面这个只能区分错误后面的..] <?php $str1 ="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwgg ...
- 完美解决 向UILable 文字最后插入N张图片,支持向限制行数的UILable 最后一行插入,多余文字显示...
效果: ====直接上代码吧=== // // UILabel+StringFrame.h // QYER // // Created by qyer on 15/3/19. // Copyright ...
随机推荐
- ew代理实战
前言 渗透内网代理必不可少,本文做个记录 正文 工具下载地址 http://rootkiter.com/EarthWorm/ ssocksd开启 socks5 代理 环境 代理:192.168.211 ...
- cnpm 淘宝镜像设置
很简单,一句话 npm install -g cnpm --registry=https://registry.npm.taobao.org
- Storm默认配置 default.yaml
default.yaml文件所在位置:apache-storm-0.9.4.tar.gz/apache-storm-0.9.4/lib/storm-core-0.94.jar/default.yaml ...
- python实现字符串中的半全角转换
全角和半角的空格的Unicode值相差12256 除空格外的全角和半角的Unicode值相差65248 # -*- coding: utf-8 -*- def strQ2B(ustring): &qu ...
- 实用vim 130+命令
基本命令 :e filename Open filename for edition :w Save file :q Exit Vim :q! Quit without saving :x Write ...
- Oracle常见等待事件
1Buffer busy waits从本质上讲,这个等待事件的产生仅说明了一个会话在等待一个Buffer(数据块),但是导致这个现象的原因却有很多种.常见的两种是: · 当一个会话视图 ...
- Hadoop HBase概念学习系列之行、行键(十一)
行是由列簇中的列组成.行根据行键依照字典顺序排序. HBase的行使用行键标识,可以使用行键查询整行的数据. 对同一个行键的访问都会落在同样的物理节点上.如果表包含2个列簇,属于两个列簇的文件还是保存 ...
- Shell中, 退出整个脚本
常规做法 cat >test.sh<<EOF'' #!/bin/bash exit_script(){ exit 1 } echo "before exit" e ...
- ArcGIS Engine开发基础总结(一)
标准Engine功能 地图浏览 地图制作 数据查询 数据分析 及 所有的开发控件 —MapControl, PageLayout, Toolbar, TOC, ArcReader 对所有矢量和栅 ...
- T-SQL 标识符
在T-SQL语言中,对SQLServer数据库及其数据对象(比如表.索引.视图.存储过程.触发器等)需要以名称来进行命名并加以区分,这些名称就称为标识符. 通常情况下,SQLServer数据库.数据库 ...