Forkingdog and masonry for automatic calculation of row heights

Source: Internet
Author: User

#import "TableViewController.h" #import "fdModel.h" #import "fdTableViewCell.h" #import <MJExtension.h> #import " Uitableview+fdtemplatelayoutcell.h "@interface Tableviewcontroller () @property (nonatomic, copy) Nsarray *fdarray;@    End@implementation tableviewcontroller-(void) viewdidload {[Super viewdidload];    [Self.tableview Registerclass:[fdtableviewcell class] forcellreuseidentifier:@ "cell"];//    Self.tableView.separatorStyle = Uitableviewcellseparatorstylenone; Self.tableView.backgroundColor = [Uicolor colorwithred:231/255.0 green:231/255.0 blue:231/255.0 alpha:1];} #pragma mark-table View data source-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section {return self.fdArray.count;} -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {Fdtablevie    Wcell *cell = [TableView dequeuereusablecellwithidentifier:@ "Cell"];    Cell.fdmodel = Self.fdarray[indexpath.row]; Cell.selectionstyLe = Uitableviewcellselectionstylenone; return cell;} -(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{return [Self.tablevi EW fd_heightforcellwithidentifier:@ "Cell" Cachebyindexpath:indexpath configuration:^ (Fdtableviewcell *cell) {cell.    Fdmodel = Self.fdarray[indexpath.row]; }];}        #pragma mark-lazyload-(Nsarray *) Fdarray {if (_fdarray = = nil) {_fdarray = [[Nsarray alloc] init];        NSString *filepath = [[NSBundle mainbundle] pathforresource:@ "microblog" oftype:@ "plist"];    _fdarray = [Fdmodel Objectarraywithfile:filepath]; } return _fdarray;}

Cell layout

#import "fdTableViewCell.h" #import "fdModel.h" #import <Masonry.h> @interface Fdtableviewcell () @property ( Nonatomic, Strong) UIView *publicview, @property (nonatomic, strong) UILabel *textlab; @property (nonatomic, Strong) UILabel *namelable; @property (nonatomic, strong) Uiimageview *iconview; @property (nonatomic, strong) Uiimageview * Vipview; @property (nonatomic, strong) Uiimageview *picview; @end @implementation fdtableviewcell-(instancetype) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) Reuseidentifier {if (self = [Super Initwiths        Tyle:style Reuseidentifier:reuseidentifier]) {[Self createview];    [Self setviewautolayout]; } return self;}    -(void) CreateView {self.publicview = [[UIView alloc] init];        [Self.contentview AddSubview:self.publicView];    Self.iconview = [[Uiimageview alloc] init];        [Self.publicview AddSubview:self.iconView];    self.namelable = [[UILabel alloc] init]; [Self.publicview AddsubviEw:self.nameLable];    Self.vipview = [[Uiimageview alloc] init];    Self.vipView.image = [UIImage imagenamed:@ "VIP"];        [Self.publicview AddSubview:self.vipView];    Self.textlab = [[UILabel alloc] init];    Self.textLab.numberOfLines = 0;        [Self.publicview AddSubview:self.textLab];    Self.picview = [[Uiimageview alloc] init]; [Self.publicview AddSubview:self.picView];} -(void) setviewautolayout {[Self.publicview mas_makeconstraints:^ (Masconstraintmaker *make) {make.t        Op.equalto (@10);        Make.left.equalTo (@10); Make.right.equalTo (@-10);
Here is the point ... Make.bottom.equalTo (Self.contentView.mas_bottom). With.offset (-10); }]; [Self.iconview mas_makeconstraints:^ (Masconstraintmaker *make) {Make.top.equalTo (@10); Make.left.equalTo (@10); Make.width.equalTo (@44); Make.height.equalTo (@44); }]; [Self.namelable mas_makeconstraints:^ (Masconstraintmaker *make) {Make.top.equalTo (@10); Make.left.equalTo (self.iconView.mas_right). With.offset (10); }]; [Self.namelable SizeToFit]; [Self.vipview mas_makeconstraints:^ (Masconstraintmaker *make) {Make.top.equalTo (@10); Make.left.equalTo (self.nameLable.mas_right). With.offset (10); Make.height.equalTo (@15); Make.width.equalTo (@15); }]; [Self.textlab mas_makeconstraints:^ (Masconstraintmaker *make) {Make.top.equalTo (Self.iconView.mas_bottom). With.offset (10); Make.left.equalTo (Self.iconview); Make.right.equalTo (@-20); }]; [Self.picview Mas_makeconstraints:^ (Masconstraintmaker *make) {make.top.equalTo (Self.textLab.mas_bottom). With.offset (10); Make.left.equalTo (Self.textlab);//This is the focus ... Make.bottom.equalTo (Self.contentview); }]; }-(void) Setfdmodel: (Fdmodel *) Fdmodel {_fdmodel = Fdmodel; Self.iconView.image = [UIImage ImageNamed:fdModel.icon]; Self.nameLable.text = Fdmodel.name; Self.vipView.hidden = (![ FDMODEL.VIP isequal:@1]); Self.textLab.text = Fdmodel.text; Self.picView.image = [fdmodel.picture length] > 0? [UIImage ImageNamed:fdModel.picture]: nil;}

Forkingdog and masonry for automatic calculation of row heights

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.