t頭文件框架
//開源框架ide
#import "MLLinkLabel.h"google
//設置代理spa
//模擬數據.net
NSArray *commentArr = @[ @{@"1":@"張三",3d
@"2":@"李四",代理
@"3":@"你在幹嗎?"},orm
@{@"1":@"李四",ip
@"2":@"張三",ci
@"3":@"吃飯睡覺看電影吃飯睡覺看電影吃飯睡覺看電影吃飯睡覺看電影吃飯睡覺看電影吃飯睡覺看電影吃飯睡覺看電影覺看電影吃飯睡覺看電影吃飯睡覺看電影"}];
[self initBottomCommentView:commentArr];
//底部評論
- (void)initBottomCommentView:(NSArray *)commentListArray
{
if (commentListArray) {
NSMutableArray *labelHeight = [NSMutableArray new];
// for (MLLinkLabel *label in _commentViewArray) {
// [label removeFromSuperview];
// }
// [_commentViewArray removeAllObjects];
[labelHeight removeAllObjects];
for (int i = 0; i < commentListArray.count; i++) {
NSDictionary *dic = [commentListArray objectAtIndex:i];
_mlLinkLabel = [[MLLinkLabel alloc] init];
_mlLinkLabel.numberOfLines = 0;
_mlLinkLabel.font = [UIFont systemFontOfSize:13];
_mlLinkLabel.backgroundColor = kBackgrondColor;
_mlLinkLabel.lineHeightMultiple = 0.0f;
_mlLinkLabel.lineSpacing = 0.0f;
_mlLinkLabel.beforeAddLinkBlock = nil;
_mlLinkLabel.dataDetectorTypes = MLDataDetectorTypeAttributedLink;
_mlLinkLabel.allowLineBreakInsideLinks = YES;
_mlLinkLabel.linkTextAttributes = nil;
_mlLinkLabel.activeLinkTextAttributes = nil;
_mlLinkLabel.tag = i;
_mlLinkLabel.delegate = self;
NSString *commentStr = [NSString new];
commentStr = [NSString stringWithFormat:@"%@回覆%@:%@",dic[@"1"],dic[@"2"],dic[@"3"]];
NSInteger rangeIndex = [dic[@"1"] length];
NSInteger rangeIndex2 = [dic[@"2"] length];
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:commentStr];
[attrStr addAttribute:NSLinkAttributeName value:@"http://google.com" range:NSMakeRange(0, rangeIndex)];
[attrStr addAttribute:NSLinkAttributeName value:@"http://google.com" range:NSMakeRange(rangeIndex+2, rangeIndex2)];
_mlLinkLabel.attributedText = attrStr;
[_mlLinkLabel invalidateDisplayForLinks];
[self addSubview:_mlLinkLabel];
CGFloat height = [self sizeWithWidth:kWIDTH - 70 height:MAXFLOAT text:commentStr font:[UIFont systemFontOfSize:13]].height;
[labelHeight addObject:@(height)];
float hheight = 0;
for (int i = 0; i < labelHeight.count; i++) {
hheight += [labelHeight[i] floatValue];
}
_commentHeight = hheight;
hheight = hheight - [[labelHeight lastObject] floatValue];
[_mlLinkLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_dateLab.mas_bottom).offset(10 + hheight);
make.left.equalTo(@60);
make.size.equalTo(MASBoxValue(CGSizeMake(kWIDTH - 70, height + 1)));
}];
// [_commentViewArray addObject:_mlLinkLabel];
}
}
}
//計算高度
- (CGSize)sizeWithWidth:(float)widet height:(float)height text:(NSString *)text font:(UIFont *)font
{
CGSize size = [text boundingRectWithSize:CGSizeMake(widet, height) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:font}context:nil].size;
return size;
}
//默認區域點擊
- (void)didClickDefaultLinkLabel:(MLLinkLabel *)linkLabel{
linkLabel.highlighted = YES;
linkLabel.highlightedTextColor = [UIColor colorWithRed:0.219 green:0.626 blue:0.950 alpha:1.000];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
linkLabel.highlighted = NO;
linkLabel.highlightedTextColor = [UIColor blackColor];
});
}
//名稱點擊時間
- (void)didClickLink:(MLLink*)link linkText:(NSString*)linkText linkLabel:(MLLinkLabel*)linkLabel{
}