UItextView,UIscrollView,UITableViewCell三种能够使页面滑动控件的总结(3)

UITableViewcell

先自定义一个属性

@property(nonatomic, retain) UITableView *tableView;

在.h中遵循协议,有两个协议需要遵循

#import <UIKit/UIKit.h>

@interface MainViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>

@end
UITableViewDataSource里面有两个必须实现的方法

<span style="font-size:14px;color:#000000;">//分区行数,
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
//cell,可以用系统定义好的cell,也可以用自定义的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;</span>

<span style="color:#000000;">//初始化方法
self.tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
//背景颜色
 self.tableView.backgroundColor = [UIColor grayColor];
//分界线颜色
 self.tableView.separatorColor = [UIColor cyanColor];
//设置代理,两个代理
 self.tableView.dataSource = self;
    self.tableView.delegate = self;</span> 

配合UITableViewCell使用,计算cell高度

 //计算文本高度的核心方法
    //boundingRectWithSize:当获取指定文字高度的时候需要一个cgsize类型的参数,需要让这个文字在限定的宽度和高度区域内显示,通常宽度和高度显示的lable的宽度保持一致,高度尽可能的设置高一点
    //options:实现显示的方式
    //attributes:设置文字相关的一些属性,当设置文字字体大小时需要跟将要显示的label字体保持一致
    //context:文本绘制的上下文,一般不需要做设置,直接写nil

CGRect textRect = [carIntroduce boundingRectWithSize:CGSizeMake(kWidth * 0.75, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15]} context:nil];

根据计算CGRect计算出来的高度去改变cell的高度,就能把所需要的东西都显示出来


计算cell自定义高度的方法

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值