无标题文章

YYText

//// KL_TableViewCell.m// instrumentTest//// Created by 行者 on 2017/12/21.// Copyright © 2017年 行者. All rights reserved.//#import "KL_TableViewCell.h"#import#import#define ImageHeight 100

@interface KL_TableViewCell()

@property (nonatomic, strong) YYLabel *label;

@property (nonatomic, strong) UIImageView *testImageview;

@property (nonatomic, copy) NSString *text;

@property (nonatomic,assign) CGFloat labelHeight;

@end

@implementation KL_TableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

if (self) {

[self viewInit];

}

return self;

}

- (void)viewInit{

_label = [YYLabel new];

_label.userInteractionEnabled = YES;

_label.numberOfLines = 0;

_label.font = [UIFont systemFontOfSize:16];

_label.textVerticalAlignment = YYTextVerticalAlignmentCenter;

[self.contentView addSubview:_label];

[_label mas_makeConstraints:^(MASConstraintMaker *make) {

make.left.mas_equalTo(10);

make.right.mas_equalTo(-10);

make.top.mas_equalTo(5);

make.height.mas_lessThanOrEqualTo(1000);

}];

_label.layer.borderWidth = 0.5;

_label.layer.borderColor = [UIColor colorWithRed:0.000 green:0.463 blue:1.000 alpha:1.000].CGColor;

[self addSeeMoreButton];

self.testImageview = [UIImageView new];

_testImageview.backgroundColor = [UIColor orangeColor];

[self.contentView addSubview:_testImageview];

[_testImageview mas_makeConstraints:^(MASConstraintMaker *make) {

make.top.equalTo(_label.mas_bottom).offset(10);

make.left.right.equalTo(_label);

make.height.mas_equalTo(100);

}];

}

- (void)layoutSubviews{

[super layoutSubviews];

[_testImageview mas_remakeConstraints:^(MASConstraintMaker *make) {

make.top.equalTo(_label.mas_bottom).offset(10);

make.left.right.equalTo(_label);

make.height.mas_equalTo(100);

}];

}

- (void)addSeeMoreButton {

__weak typeof(self)_self = 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) {

dispatch_async(dispatch_get_main_queue(), ^{

YYLabel *label = _self.label;

[label sizeToFit];

_self.labelHeight = label.bounds.size.height;

self.block(_self.labelHeight,_self);

[self layoutIfNeeded];

});

};

[text yy_setColor:[UIColor colorWithRed:0.000 green:0.449 blue:1.000 alpha:1.000]range:[text.string rangeOfString:@"more"]];

[text yy_setTextHighlight:hi range:NSMakeRange(3, 2)];

text.yy_font =_label.font;

YYLabel *seeMore = [YYLabel new];

seeMore.attributedText = text;

[seeMore sizeToFit];

NSAttributedString *truncationToken = [NSAttributedString yy_attachmentStringWithContent:seeMore contentMode:UIViewContentModeBottomRight attachmentSize:seeMore.frame.size alignToFont:text.yy_font alignment:YYTextVerticalAlignmentCenter];

_label.truncationToken = truncationToken;

}

- (void)setData:(NSString *)text height:(CGFloat)height{

NSMutableAttributedString *test = [NSMutableAttributedString new];

UIFont *font = [UIFont systemFontOfSize:16];

[test appendAttributedString:[[NSAttributedString alloc] initWithString:text attributes:nil]];

test.yy_font = font ;

_label.attributedText = test;

[_label mas_remakeConstraints:^(MASConstraintMaker *make) {

make.left.mas_equalTo(10);

make.right.mas_equalTo(-10);

make.top.mas_equalTo(5);

make.height.mas_equalTo(height);

}];

[_testImageview mas_remakeConstraints:^(MASConstraintMaker *make) {

make.top.equalTo(_label.mas_bottom).offset(10);

make.left.right.equalTo(_label);

make.height.mas_equalTo(100);

}];

}

- (void)awakeFromNib {

[super awakeFromNib];

// Initialization code

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

[super setSelected:selected animated:animated];

// Configure the view for the selected state

}

@end


//// ViewController.m// instrumentTest//// Created by 行者 on 2017/11/15.// Copyright © 2017年 行者. All rights reserved.//#import "ViewController.h"#import "PlayViewController.h"#import#import#import "KL_TableViewCell.h"@interface ViewController ()@property(nonatomic, strong) YYLabel *label;@property (nonatomic, strong) UILabel *labeltext;@property (nonatomic, strong) UIImageView *testImageview;@property (nonatomic, strong) NSMutableArray *tabArr;@property (nonatomic, strong) NSMutableArray *heightArr;@end@implementation ViewController- (NSMutableArray *)tabArr{ if (!_tabArr) { _tabArr = @[@"😄😂😂😄😂😂😄👍👍👍👍👍👍😄😂😂👍👍👍👍👍👍👍👍👍👍👍👍👍👍😂😄😂😂😄😂😂😄😂😂😄😂😂😄😂😂😄45645645😂😂😄😂😂😄😂😂46564564😄😂😂😄😂😂😄😂45645645645👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍", @"你还撒谎还是复活节三闾大夫河东狮吼老邵绝代风fhsdhfsdlfhsdjhfjdskfhjskdhfjk华的身份互为彼fhsdhfsdlfhsdjhfjdskfhjskdhfjk此间的伤口恢复好的索科洛夫回到家还是短发绝对是连接方式减肥的视力恢复;hfjhsdhfjdsfhlsdljkfhsdhfsdlfhsdjhfjdskfhjskdhfjksdj闪光灯接口规范的设计风格圣诞节开发环境肯定是割发代首官方的说法高峰时段高考了", @"32874823742374098723478238742332874823742374098723478238742332874823742374098723478238742332874823742374098723478238742332874823742374098723478238742332874823742374098723478238742332874823742374098723478238742332874823742374098723478238742389748327482347382483297482347", @"hfsdlhfsdfhwwwwwwdfhjdfffdsfqwfqf;kjjfdf;[sdg;[][d;shfewuiqo iqpueq [pqjnsccxnmx>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、设置UILabel行间距 NSMutableAttributedString*attrString=[[NSM...
    iOS祎阅读 2,212评论 0 0
  • 转至元数据结尾创建: 董潇伟,最新修改于: 十二月 23, 2016 转至元数据起始第一章:isa和Class一....
    40c0490e5268阅读 1,776评论 0 9
  • 在处理蓝牙数据的时候,经常遇到进制之间的转换,蓝牙处理的是16进制(NSData),而我们习惯的计数方式是10进制...
    砖家就是我阅读 355评论 0 0
  • ``` /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject ...
    非专业码农阅读 346评论 0 0
  • JAVA面试题 1、作用域public,private,protected,以及不写时的区别答:区别如下:作用域 ...
    JA尐白阅读 1,183评论 1 0