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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IOS15使用Masonry和自动计算Cell的高度

發布時間:2023/12/18 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS15使用Masonry和自动计算Cell的高度 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

IOS15使用Masonry和自動計算Cell的高度

核心源碼

// 步驟1:tableView.rowHeight = UITableViewAutomaticDimension;// 步驟2:tableView.estimatedRowHeight = 100.0; CGFloat avatarButtonWidth = 32.0;self.avatarButton = [UIButton buttonWithType:UIButtonTypeCustom];self.avatarButton.layer.cornerRadius = avatarButtonWidth / 2.0;self.avatarButton.clipsToBounds = YES;[self.avatarButton setImage:[UIImage imageNamed:@"Avatar.jpg"] forState:UIControlStateNormal];[self.contentView addSubview:self.avatarButton];UIView *view = [[UIView alloc] init];self.nicknameLabel = [[UILabel alloc] init];self.nicknameLabel.font = [UIFont systemFontOfSize:13.0];self.nicknameLabel.textColor = [UIColor blackColor];self.nicknameLabel.text = @"昵稱";[view addSubview:self.nicknameLabel];self.timeLabel = [[UILabel alloc] init];self.timeLabel.font = [UIFont systemFontOfSize:12.0];self.timeLabel.textColor = [UIColor grayColor];self.timeLabel.text = @"4-27";[view addSubview:self.timeLabel];[self.contentView addSubview:view];self.contentLabel = [[UILabel alloc] init];self.contentLabel.numberOfLines = 0;self.contentLabel.font = [UIFont systemFontOfSize:15.0];self.contentLabel.textColor = [UIColor blackColor];[self.contentView addSubview:self.contentLabel];[self.avatarButton mas_makeConstraints:^(MASConstraintMaker *make) {// 步驟3:設置頭像的約束,最重要的思想是:給頭像的top與contentView.mas_top之間建立約束make.top.equalTo(self.contentView.mas_top).offset(27.0);// 設置size與leading(left)的約束,不解釋make.size.mas_equalTo(CGSizeMake(avatarButtonWidth, avatarButtonWidth));make.leading.equalTo(self.contentView.mas_leading).offset(20.0);}];// nicknameLabel與timeLabel也是使用了自動撐開的思想[self.nicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.leading.top.equalTo(view);}];[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.leading.equalTo(self.nicknameLabel.mas_leading);make.top.equalTo(self.nicknameLabel.mas_bottom).offset(3.0);make.bottom.equalTo(view.mas_bottom);}];[view mas_makeConstraints:^(MASConstraintMaker *make) {make.leading.equalTo(self.avatarButton.mas_trailing).offset(10.0);make.trailing.lessThanOrEqualTo(self.contentView.mas_trailing).offset(-10.0);make.centerY.equalTo(self.avatarButton.mas_centerY);}];[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {// 步驟4:設置評論的top與頭像的bottom之間的約束make.top.equalTo(self.avatarButton.mas_bottom).offset(15.0);// 步驟5:設置評論的bottom與contentView.mas_bottom之間的約束make.bottom.equalTo(self.contentView.mas_bottom).offset(-25.0);make.leading.equalTo(self.avatarButton.mas_leading);make.trailing.equalTo(self.contentView.mas_trailing).offset(-20.0);}];


https://e.coding.net/lujun1/afnetworkinggetdemo/CellAutomaticHeight.git

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的IOS15使用Masonry和自动计算Cell的高度的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。