日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

使用第三方《UITableView+FDTemplateLayoutCell》自动计算UITableViewCell高度(Masonry约束)...

發(fā)布時(shí)間:2024/4/13 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用第三方《UITableView+FDTemplateLayoutCell》自动计算UITableViewCell高度(Masonry约束)... 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

直接上代碼:

1:先自定義cell

.h文件中

#import <UIKit/UIKit.h> #import "LBDNewMsgListModel.h" #import "MLEmojiLabel.h"@interface LBDMsgCenterCell : UITableViewCell<MLEmojiLabelDelegate, UIGestureRecognizerDelegate>@property (nonatomic, strong) UILabel *msgDateLbl; @property (nonatomic, strong) UIView *bgView; @property (nonatomic, strong) UIView *topLineView; @property (nonatomic, strong) UIImageView *msgImgView; @property (nonatomic, strong) UILabel *titleLbl; @property (nonatomic, strong) UILabel *orderNum; @property (nonatomic, strong) UIView *lineView; @property (nonatomic, strong) UILabel *lookLbl; @property (nonatomic, strong) MLEmojiLabel *contentLbl;@property (nonatomic, strong) LBDNewMsgListModel *model;@end

.m文件中

#import "LBDMsgCenterCell.h" #import "LBDNewMsgListModel.h" #import "NSDate+Extend.h"@implementation LBDMsgCenterCell- (void)awakeFromNib {[super awakeFromNib];// Initialization code }- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {[self createView];[self setSubviews];}return self; }#pragma make 創(chuàng)建子控件- (void)createView {_msgDateLbl = [[UILabel alloc] init];_msgDateLbl.font = [UIFont systemFontOfSize:10];_msgDateLbl.textColor = [UIColor colorWithHex:@"646464"];_msgDateLbl.textAlignment = NSTextAlignmentCenter;[self.contentView addSubview:_msgDateLbl];_bgView = [[UIView alloc] init];_bgView.backgroundColor = [UIColor whiteColor];_bgView.layer.masksToBounds = YES;_bgView.layer.cornerRadius = 10;[self.contentView addSubview:_bgView];_msgImgView = [[UIImageView alloc] init];_msgImgView.hidden = YES;_msgImgView.contentMode = UIViewContentModeScaleToFill;[_bgView addSubview:_msgImgView];_topLineView = [[UIView alloc] init];_topLineView.hidden = YES;[_bgView addSubview:_topLineView];_titleLbl = [[UILabel alloc] init];_titleLbl.font = [UIFont systemFontOfSize:15];_titleLbl.numberOfLines = 0;_titleLbl.textColor = [UIColor colorWithHex:@"505050"];[_bgView addSubview:_titleLbl];_lookLbl = [[UILabel alloc] init];_lookLbl.textAlignment = NSTextAlignmentRight;;_lookLbl.text = @"立即查看";_lookLbl.font = [UIFont systemFontOfSize:13];[_bgView addSubview:_lookLbl];_lineView = [[UIView alloc] init];_lineView.backgroundColor = [UIColor unclickableColor];[_bgView addSubview:_lineView];[_bgView addSubview:self.contentLbl]; }- (void)setModel:(LBDNewMsgListModel *)model {NSDateFormatter *formater = [[NSDateFormatter alloc] init];formater.dateFormat = @"yyyy/MM/dd HH:mm";NSDate *sendDate = [formater dateFromString:model.createdAt];if ([sendDate isToday]) {_msgDateLbl.text = [NSString stringWithFormat:@"今天 %@", [model.createdAt timestampTransformDateToType:@"HH:mm"]];} else if ([sendDate isYesToday]) {_msgDateLbl.text = [NSString stringWithFormat:@"昨天 %@", [model.createdAt timestampTransformDateToType:@"HH:mm"]];} else {_msgDateLbl.text = [model.createdAt timestampTransformDateToType:@"yyyy/MM/dd HH:mm"];}_titleLbl.text = model.title;self.contentLbl.text = model.content;[_bgView mas_remakeConstraints:^(MASConstraintMaker *make) {make.top.mas_equalTo(_msgDateLbl.mas_bottom);make.left.mas_equalTo(self.contentView.mas_left).offset(10);make.right.mas_equalTo(self.contentView.mas_right).offset(-10);make.bottom.mas_equalTo(self.contentView.mas_bottom);}];if ([model.colorType isEqualToString:@"1"]) {_topLineView.hidden = NO;_msgImgView.hidden = YES;[_msgImgView sd_setImageWithURL:nil];_topLineView.backgroundColor = [UIColor redColor];[_topLineView mas_remakeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(_bgView.mas_left);make.top.mas_equalTo(_bgView.mas_top);make.right.mas_equalTo(_bgView.mas_right);make.height.mas_equalTo(5);}];[_titleLbl mas_remakeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(_bgView.mas_left).offset(10);make.right.mas_equalTo(_bgView.mas_right).offset(-10);make.top.mas_equalTo(_topLineView.mas_bottom).offset(6);}];[self.contentLbl mas_remakeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(_titleLbl.mas_left);make.right.mas_equalTo(_titleLbl.mas_right);make.top.mas_equalTo(_titleLbl.mas_bottom).offset(8);}];} else if ([model.colorType isEqualToString:@"2"]) {_topLineView.hidden = NO;_msgImgView.hidden = YES;[_msgImgView sd_setImageWithURL:nil];_topLineView.backgroundColor = [UIColor colorWithHex:@"00ade5"];[_topLineView mas_remakeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(_bgView.mas_left);make.top.mas_equalTo(_bgView.mas_top);make.right.mas_equalTo(_bgView.mas_right);make.height.mas_equalTo(5);}];[_titleLbl mas_remakeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(_bgView.mas_left).offset(10);make.right.mas_equalTo(_bgView.mas_right).offset(-10);make.top.mas_equalTo(_topLineView.mas_bottom).offset(6);}];[self.contentLbl mas_remakeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(_titleLbl.mas_left);make.right.mas_equalTo(_titleLbl.mas_right);make.top.mas_equalTo(_titleLbl.mas_bottom).offset(8);}];} else if ([model.colorType isEqualToString:@"3"]) {_topLineView.hidden = YES;_msgImgView.hidden = NO;[_topLineView mas_remakeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(_bgView.mas_left);make.top.mas_equalTo(_msgDateLbl.mas_bottom);make.right.mas_equalTo(_bgView.mas_right);make.height.mas_equalTo(0);}];[_msgImgView sd_setImageWithURL:[NSURL URLWithString:model.activityImg] placeholderImage:[UIImage imageNamed:@"PersonalInformationImagePlaceholder"]];[_msgImgView mas_remakeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(_bgView.mas_left);make.right.mas_equalTo(_bgView.mas_right);make.top.mas_equalTo(_msgDateLbl.mas_bottom);make.height.mas_equalTo(SCREEN_WIDTH / 3.41);}];[_titleLbl mas_remakeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(_bgView.mas_left).offset(10);make.right.mas_equalTo(_bgView.mas_right).offset(-10);make.top.mas_equalTo(_msgImgView.mas_bottom).offset(6);}];[_contentLbl mas_remakeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(_titleLbl.mas_left);make.right.mas_equalTo(_titleLbl.mas_right);make.top.mas_equalTo(_titleLbl.mas_bottom).offset(8);}];}if ([model.jump isEqualToString:@"0"]) {[_lineView mas_remakeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(self.contentLbl.mas_left);make.right.mas_equalTo(self.contentLbl.mas_right);make.height.mas_equalTo(0);make.top.mas_equalTo(self.contentLbl.mas_bottom);}];[_lookLbl mas_remakeConstraints:^(MASConstraintMaker *make) {make.right.mas_equalTo(self.contentLbl.mas_right);make.width.mas_equalTo(80);make.height.mas_equalTo(0);make.top.mas_equalTo(_lineView.mas_bottom);make.bottom.mas_equalTo(_bgView.mas_bottom);}];} else if ([model.jump isEqualToString:@"1"]) {[_lineView mas_remakeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(self.contentLbl.mas_left);make.right.mas_equalTo(self.contentLbl.mas_right);make.height.mas_equalTo(0.5);make.top.mas_equalTo(self.contentLbl.mas_bottom);}];[_lookLbl mas_remakeConstraints:^(MASConstraintMaker *make) {make.right.mas_equalTo(self.contentLbl.mas_right);make.width.mas_equalTo(100);make.height.mas_equalTo(30);make.top.mas_equalTo(_lineView.mas_bottom);make.bottom.mas_equalTo(_bgView.mas_bottom);}];}}- (void)setSubviews {[_msgDateLbl mas_makeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(self.contentView.mas_left);make.top.mas_equalTo(self.contentView.mas_top);make.right.mas_equalTo(self.contentView.mas_right);make.height.mas_equalTo(30);}]; }#pragma mark - delegate- (void)mlEmojiLabel:(MLEmojiLabel*)emojiLabel didSelectLink:(NSString*)link withType:(MLEmojiLabelLinkType)type {switch(type){case MLEmojiLabelLinkTypeURL:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:link]];break;case MLEmojiLabelLinkTypePhoneNumber:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", link]]];break;case MLEmojiLabelLinkTypeEmail:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"mailto:%@", link]]];break;case MLEmojiLabelLinkTypeAt:NSLog(@"點(diǎn)擊了用戶%@",link);break;case MLEmojiLabelLinkTypePoundSign:NSLog(@"點(diǎn)擊了話題%@",link);break;default:NSLog(@"點(diǎn)擊了不知道啥%@",link);break;}}- (MLEmojiLabel *)contentLbl {if (!_contentLbl) {_contentLbl = [MLEmojiLabel new];_contentLbl.numberOfLines = 0;_contentLbl.font = [UIFont systemFontOfSize:13.0f];_contentLbl.delegate = self;_contentLbl.backgroundColor = [UIColor whiteColor];_contentLbl.lineBreakMode = NSLineBreakByTruncatingTail;_contentLbl.textColor = [UIColor colorWithHex:@"a0a0a0"];_contentLbl.disableEmoji = NO;_contentLbl.lineSpacing = 3.0f;_contentLbl.verticalAlignment = TTTAttributedLabelVerticalAlignmentCenter;}return _contentLbl; }

?

2:在控制器.m文件中使用

- (void)drawView {_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];_tableView.backgroundColor = [UIColor bgColor];_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;_tableView.delegate = self;_tableView.dataSource = self;[self addSubview:_tableView];// 給一個(gè)標(biāo)識(shí)符,告訴tableView要?jiǎng)?chuàng)建哪個(gè)類[_tableView registerClass:[LBDMsgCenterCell class] forCellReuseIdentifier:@"LBDMsgCenterCell"];}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {return [self.tableView fd_heightForCellWithIdentifier:@"LBDMsgCenterCell" cacheByIndexPath:indexPath configuration:^(LBDMsgCenterCell *cell) {// 在這個(gè)block中,重新cell配置數(shù)據(jù)源 [self setupModelOfCell:cell atIndexPath:indexPath];}]; }- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {return _msgArr.count; }- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {LBDMsgCenterCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LBDMsgCenterCell"];cell.selectionStyle = UITableViewCellSelectionStyleNone;cell.backgroundColor = [UIColor clearColor];[self setupModelOfCell:cell atIndexPath:indexPath];return cell; }- (void)setupModelOfCell:(LBDMsgCenterCell *) cell atIndexPath:(NSIndexPath *) indexPath {// 采用計(jì)算frame模式還是自動(dòng)布局模式,默認(rèn)為NO,自動(dòng)布局模式// cell.fd_enforceFrameLayout = NO;cell.model = _msgArr[indexPath.row]; }

轉(zhuǎn)載于:https://www.cnblogs.com/xuzb/p/8706737.html

總結(jié)

以上是生活随笔為你收集整理的使用第三方《UITableView+FDTemplateLayoutCell》自动计算UITableViewCell高度(Masonry约束)...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产91在线高潮白浆在线观看 | 久久成人精品视频 | 国产99久一区二区三区a片 | 黄色网址多少 | 极品美女销魂一区二区三区 | 日韩国产欧美一区二区三区 | 亚洲码无人客一区二区三区 | 鲁一鲁一鲁一鲁一av | 日b视频在线观看 | 久久99亚洲精品 | 日日夜夜综合网 | 丁香六月婷婷激情 | 欧美精品亚洲精品 | 国产精品一区二区三区不卡 | 青青草婷婷 | 大奶在线播放 | 天天爱天天射 | 国产伦精品一区二区三区视频免费 | 131美女爱做视频 | 四虎视频国产精品免费入口 | 国产一二三在线 | 国产精品久久av无码一区二区 | 99精品在线 | 毛片毛片女人毛片毛片 | 91干干| 色老头影视 | 第一福利在线 | 欧美人与动性xxxxx杂性 | 丁香五色月| 三上悠亚激情av一区二区三区 | 9人人澡人人爽人人精品 | 久久成人毛片 | 91精品国 | 色啪网站 | 天天爱天天做 | 偷偷操99 | 国产91一区二区三区在线精品 | 免费看一级黄色大全 | 男人视频网 | 成人欧美一区二区三区在线观看 | 高清欧美性猛交xxxx黑人猛交 | 国产精品久久毛片av大全日韩 | 欧美噜噜噜 | 天天鲁一鲁摸一摸爽一爽 | 亚洲欧美天堂网 | 一区二区在线免费观看视频 | 在线观看黄网 | 亚洲成年人在线 | 男人与雌性宠物交啪啪 | 男人天堂2019| 国产又粗又猛又爽视频 | 日韩一三区 | 蜜臀av一区二区三区激情综合 | 高潮无码精品色欲av午夜福利 | 啊av在线| 福利视频在线 | 有码在线播放 | 蜜臀99久久精品久久久久久软件 | 夜夜嗨视频 | 少妇一晚三次一区二区三区 | 欧美亚洲精品一区二区 | 三上悠亚影音先锋 | 色欲AV无码精品一区二区久久 | 天天碰天天干 | 免费看黄色网 | 午夜宅男在线 | 国产精品免费视频观看 | 成人av图片 | 国产精品视频免费看 | 芒果视频污污 | 国产ts网站 | 亚洲一区,二区 | 超碰在线个人 | 综合狠狠| 亚洲亚洲人成综合网络 | 天天碰免费视频 | 狠狠躁夜夜躁人人爽视频 | 五月天黄色网 | 四虎影库在线播放 | 高清中文字幕 | 国产怡红院 | 四虎免费在线观看 | 日韩福利一区二区 | 欧美一级视频免费 | 欧美一区二区三区在线视频 | 欧美精品乱人伦久久久久久 | 国产一区视频观看 | 亚洲精品久久久中文字幕 | 中文字幕日韩欧美一区二区 | 黑料视频在线 | 中文在线а√天堂 | 在线观看日韩国产 | 九九热视频精品在线观看 | 日韩av无码中文字幕 | 天天欲色 | 午夜免费视频网站 | 亚洲 欧美 综合 | 欧美一区二区福利 | 欧美youjizz |