无标题文章

2017-12-22  本文已影响0人  爱吃兽奶奶

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>

上一篇下一篇

猜你喜欢

热点阅读