天天看點

IOS SDautolayout架構學習

SDautolayout架構

導入SDautolayout架構

​ 1.cd (需要導入架構的檔案)

​ 2.pod init

IOS SDautolayout架構學習

3.然後打開項目檔案夾打開裡面的Podfile檔案

IOS SDautolayout架構學習

4.修改Podfile檔案的内容

IOS SDautolayout架構學習

​ 5.然後回到終端輸入指令

​ 5.1pod install

​ 5.2等到install完成再輸入pod setup

​ 6.這樣就已經成功将SDAutolayout架構導入進檔案了

解決SDAutolayout架構的#import問題

雖然隻是導入了SDautolayout架構,但是是不能敲出SDautolayout.h的頭檔案的

​ 1.

IOS SDautolayout架構學習

2.

IOS SDautolayout架構學習

3.

IOS SDautolayout架構學習

​ 4.這樣就可以有提示地敲出SDautolayout.h了

SDautolayout架構的使用

​ 1.首先導入頭檔案SDautolayout.h

​ 2.要注意的是

​ 2.1要先把控件添加到父控件中才去添加限制

​ 2.2 如果是在自定的cell上,那就要把子控件添加到self.contentview

//呢稱
    self.nameLabel.text = user.name;
    self.nameLabel.sd_layout
    .leftSpaceToView(self.iconView, 10)
    .topEqualToView(self.iconView)
    .widthIs(200)
    .autoHeightRatio(0);

           
IOS SDautolayout架構學習

​ 3.如果是在自定義的cell内部設定限制

​ 3.1為了做到cell的自适應高度

​ 1.在設定子控件的最後加上這一句

2.然後在tableViewCell傳回高度那裡設定為
           
//cell的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return [self cellHeightForIndexPath:indexPath cellContentViewWidth:self.view.frame.size.width tableView:tableView];
}
           

SDautolayout架構的更多應用

https://blog.csdn.net/grl18840839630/article/details/78215324?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-5