美文网首页iOS开发技术分享
contentOffset、contentSize和conten

contentOffset、contentSize和conten

作者: 天亮説晚安 | 来源:发表于2016-01-22 09:35 被阅读247次

    1、UIScrollView
    @property(nonatomic)CGPoint contentOffset;
    这个属性用来表示UIScrollView滚动的位置

    @property(nonatomic)CGSize contentSize;
    这个属性用来表示UIScrollView内容的尺寸,滚动范围(能滚多远)

    @property(nonatomic)UIEdgeInsets contentInset;
    这个属性能够在UIScrollView的4周增加额外的滚动区域

    屏幕快照 2016-01-22 下午8.27.18.png

    2、UITableView
    UITableView是UIScrollView的子类,tabelview的contentsize是由它的下列方法共同实现的

    - (NSInteger)numberOfSections;
    - (NSInteger)numberOfRowsInSection:(NSInteger)section;
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
    

    它会自动计算所有的高度和来做为它的contentsize的height.

    例如你在delegate方法

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    {
        return 100;
    }
    

    那么你的tabelview的contentsize就是(320, 4400)

    如果是一个空的tableview,里面什么都没有设置,它就默认你的contentsize是(width ,0)了,所以它也不会有offset和inset了,如果你设置了它的行数(必须设置,否则默认是0)和每一行的高度(这个可以不设置,默认是44),那么它会自动计算contentsize了,这个时候tableview才可以拖动。

    相关文章

      网友评论

        本文标题:contentOffset、contentSize和conten

        本文链接:https://www.haomeiwen.com/subject/lealkttx.html