亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

詳解iOS tableViewCell自適應(yīng)高度 第三發(fā)類庫

 更新時(shí)間:2016年04月15日 11:02:13   作者:徒步天涯  
在github中有許多大牛封裝好的第三發(fā)類庫,其中有個(gè)自適應(yīng)cell高度的類庫。接下來通過本文給大家介紹iOS tableViewCell自適應(yīng)高度 第三發(fā)類庫,需要的朋友參考下

在github中有許多大牛封裝好的第三發(fā)類庫,其中有個(gè)自適應(yīng)cell高度的類庫

下載地址:https://github.com/gsdios/SDAutoLayout

model類

commentsModel
#import "JSONModel.h"
#import "getCommentData.h"
@interface commentsModel : JSONModel
@property(nonatomic,copy)NSArray<getCommentData> *commentList;
@end 
#import "commentsModel.h"
@implementation commentsModel
@end 
getCommentData
#import "JSONModel.h"
@protocol getCommentData
@end
@interface getCommentData : JSONModel
@property(nonatomic,copy)NSString *message;
@property(nonatomic,copy)NSString *nickName;
@property(nonatomic,copy)NSString *createTimeStr;
@end 
#import "getCommentData.h"
@implementation getCommentData
@end 

控制器

#import "commentsTableViewController.h"
#import "commentsModel.h"
#import "commentCell.h"
@interface commentsTableViewController ()
@property(nonatomic,strong)NSArray *commentsArray;
@end
@implementation commentsTableViewController
-(NSArray *)commentsArray{
if (_commentsArray==nil) {
NSData *data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"comment_list.json" ofType:nil]];
commentsModel *commensM=[[commentsModel alloc]initWithData:data error:nil];
_commentsArray=commensM.commentList;
}
return _commentsArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.commentsArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *ID=@"comment";
commentCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
if (cell==nil) {
cell=[[commentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
}
cell.commentData=self.commentsArray[indexPath.row];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return [self cellHeightForIndexPath:indexPath cellContentViewWidth:[self cellContentViewWith]];
}
-(CGFloat)cellContentViewWith{
CGFloat width=[UIScreen mainScreen].bounds.size.width;
if ([UIApplication sharedApplication].statusBarOrientation != UIInterfaceOrientationPortrait && [[UIDevice currentDevice].systemVersion floatValue] < 8) {
width = [UIScreen mainScreen].bounds.size.height;
}
return width;
}
@end 

具體自定義cell的代碼

#import <UIKit/UIKit.h>
@class getCommentData;
@interface commentCell : UITableViewCell
@property(nonatomic,strong)getCommentData *commentData;
@property(nonatomic,strong)UILabel *nameLabel;
@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UILabel *dateLabel;
@end 
#import "commentCell.h"
#import "commentsModel.h"
@implementation commentCell
-(void)setCommentData:(getCommentData *)commentData{
_commentData=commentData;
_titleLabel.text=commentData.message;
_dateLabel.text=commentData.createTimeStr;
_nameLabel.text=commentData.nickName;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self setup];
}
return self;
}
-(void)setup{
_nameLabel=[UILabel new];
[self.contentView addSubview:_nameLabel];
_nameLabel.textColor=[UIColor colorWithRed:0.891 green:0.549 blue:0.073 alpha:1.000];
_nameLabel.font=[UIFont systemFontOfSize:15];
_nameLabel.numberOfLines=1;
_titleLabel=[UILabel new];
[self.contentView addSubview:_titleLabel];
_titleLabel.textColor=[UIColor darkGrayColor];
_titleLabel.font=[UIFont systemFontOfSize:15];
_titleLabel.numberOfLines=0;
_dateLabel=[UILabel new];
[self.contentView addSubview:_dateLabel];
_dateLabel.textColor=[UIColor colorWithRed:0.679 green:0.166 blue:0.828 alpha:1.000];
_dateLabel.font=[UIFont systemFontOfSize:15];
_dateLabel.numberOfLines=1;
CGFloat margin=10;
UIView *contentView=self.contentView;
_nameLabel.sd_layout
.leftSpaceToView(contentView,margin)
.topSpaceToView(contentView,margin)
.rightSpaceToView(contentView,margin)
.heightIs(20);
_titleLabel.sd_layout
.leftSpaceToView(contentView,margin)
.topSpaceToView(_nameLabel,2)
.rightSpaceToView(contentView,margin)
.autoHeightRatio(0);
_dateLabel.sd_layout
.leftSpaceToView(contentView,margin)
.topSpaceToView(_titleLabel,5)
.heightIs(20)
.widthIs(150);
[self setupAutoHeightWithBottomViewsArray:@[_titleLabel,_dateLabel,_nameLabel] bottomMargin:margin];
}
- (void)awakeFromNib {
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
@end 

相關(guān)文章

  • IOS Xcode調(diào)試常用命令和斷點(diǎn)整理

    IOS Xcode調(diào)試常用命令和斷點(diǎn)整理

    這篇文章主要介紹了IOS Xcode調(diào)試常用命令和斷點(diǎn)整理的相關(guān)資料,這里對(duì)IOS Xcode調(diào)試常用命令進(jìn)行了總結(jié),需要的朋友可以參考下
    2016-12-12
  • iOS沙盒視頻縮略圖及保存本地代碼

    iOS沙盒視頻縮略圖及保存本地代碼

    這篇文章主要為大家詳細(xì)介紹了iOS沙盒視頻縮略圖及保存本地的代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • Objective-C中編程中一些推薦的書寫規(guī)范小結(jié)

    Objective-C中編程中一些推薦的書寫規(guī)范小結(jié)

    這篇文章主要介紹了Objective-C的一些編程書寫規(guī)范小結(jié),包括類與方法等面向?qū)ο缶幊滔嚓P(guān)的代碼編寫風(fēng)格,需要的朋友可以參考下
    2016-04-04
  • iOS DropDown下拉按鈕效果代碼分享

    iOS DropDown下拉按鈕效果代碼分享

    這篇文章主要為大家詳細(xì)介紹了iOS DropDown下拉按鈕效果的實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • 禁止iPhone Safari video標(biāo)簽視頻自動(dòng)全屏的辦法

    禁止iPhone Safari video標(biāo)簽視頻自動(dòng)全屏的辦法

    本篇文章給大家分析有沒有辦法禁止iPhone Safari video標(biāo)簽視頻自動(dòng)全屏,以下給出好多種情況分享,感興趣的朋友可以參考下
    2015-09-09
  • iOS仿小紅書呼吸燈動(dòng)畫(核心動(dòng)畫和定時(shí)器)兩種方式實(shí)現(xiàn)

    iOS仿小紅書呼吸燈動(dòng)畫(核心動(dòng)畫和定時(shí)器)兩種方式實(shí)現(xiàn)

    本篇文章主要介紹了iOS仿小紅書呼吸燈動(dòng)畫(核心動(dòng)畫和定時(shí)器)兩種方式實(shí)現(xiàn),非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2017-04-04
  • iOS NSURLSessionDownloadTask設(shè)置代理文件下載的示例

    iOS NSURLSessionDownloadTask設(shè)置代理文件下載的示例

    本篇文章主要介紹了iOS NSURLSessionDownloadTask設(shè)置代理文件下載的示例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • iOS中如何引用另一個(gè)工程的方法教程

    iOS中如何引用另一個(gè)工程的方法教程

    在iOS開發(fā)中,引用另一個(gè)工程是大家可能會(huì)遇到的一個(gè)問題,所以這篇文章主要給大家介紹了關(guān)于iOS中如何引用另一個(gè)工程的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),對(duì)各位iOS開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11
  • iOS中Runtime的幾種基本用法記錄

    iOS中Runtime的幾種基本用法記錄

    RunTime顧名思義運(yùn)行時(shí),就是系統(tǒng)在運(yùn)行的時(shí)候的一些機(jī)制,最主要的是消息機(jī)制。下面這篇文章主要給大家介紹了關(guān)于iOS中Runtime的幾種基本用法,文中通過示例代碼介紹的非常詳細(xì),需要的朋友下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07
  • iOS實(shí)現(xiàn)攝像頭實(shí)時(shí)采集圖像

    iOS實(shí)現(xiàn)攝像頭實(shí)時(shí)采集圖像

    這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)攝像頭實(shí)時(shí)采集圖像,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-04-04

最新評(píng)論