效果图:

操作

先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. MySQL的索引与优化

    写在前面:索引对查询的速度有着至关重要的影响,理解索引也是进行数据库性能调优的起点.考虑如下情况,假设数据库中一个表有10^6条记录,DBMS的页面大小为4K,并存储100条记录.如果没有索引,查询将 ...

  2. windows 静态IP设置举例

    IP 172.20.108.239 子网掩码 255.255.255.0 网关 172.20.108.1

  3. node和iisnode express手工安装

    一.安装node.js的x86版本: 这样,node.js会安装在C:\Program Files (x86)\nodejs,这符合iisnode express7版本的期待. 二.安装iisnode ...

  4. phantomJs 快速入门学习 了解大概

    1.hellow程序 一个永远的开头,创建一个文件hello.js.内容如下 //hello.js//在窗口输出信息 console.log('Hellow ,Word'); //退出程序,每个脚本必 ...

  5. [翻译] CBStoreHouseRefreshControl

    CBStoreHouseRefreshControl What is it? A fully customizable pull-to-refresh control for iOS inspired ...

  6. linux centos6.5 网络配置

    1.方法一.修改网络配置文件 ①cd /etc/sysconfig/network-scripts ②cp ifcfg-eth0  ./ifcfg-eth0.bak   //修改前先备份 第一个以太网 ...

  7. [转载]Matlab中插值函数汇总和使用说明

    http://blog.sciencenet.cn/blog-457143-679275.html MATLAB中的插值函数为interp1,其调用格式为:  yi= interp1(x,y,xi,' ...

  8. Ardunio控制RGB的LED灯显示彩虹渐变色.

    由于我使用的是共阴极的RGB LED,如果你的是共阳极的,接线的时候要注意一下. 其他没什么不同 //定义RGB色彩的输出I/O ; ; ; //标记颜色变化的方式,增加值还是减小值 bool red ...

  9. Shell中, 退出整个脚本

    常规做法 cat >test.sh<<EOF'' #!/bin/bash exit_script(){ exit 1 } echo "before exit" e ...

  10. UI(三)

    1. 2.经常用到的loadmap函数 void CTopology::LoadMap() { //m_map.RemoveAllLayers(); AddLayersBasemap(); AddLa ...