美文网首页
横向列表(当然也可以纵向)(此文本人原创需要转载请注明出处。只做

横向列表(当然也可以纵向)(此文本人原创需要转载请注明出处。只做

作者: JarodWang | 来源:发表于2016-12-19 14:26 被阅读53次

    我们在有的时候需要用到scrollview横向加载大小相同的多个控件。那么我们就需要重用啦,因为创建太多会导致内存剧增界面卡顿什么的一大堆问题,小弟想了半天整出了一个解决办法写了一个小小的demo并且封装了一下,此代码仅供各位参考。暴露的接口不是很多,如果各位有什么建议啊的写得不好的地方请多多指教,如人不在直接反馈邮箱1474961002@qq.com给小弟一点建议,进行改进大家都不容易相互帮个忙嘛,在上代码之前给进来看的小伙伴微表谢意。好上代码。

    横向的就是这样的效果,当然看到那个红色框了没?直接在上面添加控件就好了。。。方便吧哈哈😆

    */

    #import"ViewController.h"

    #import"UIListTableView.h"

    #import"UIListViewCell.h"

    @interfaceViewController(){

    UIListTableView* _tableView;

    }

    @end

    @implementationViewController

    - (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    /**

    这里我们需要注意的是我们列表的高度要根据方向来给。横向的时候我们的高度我们肯定希望我们的控件和我们的列表的高度差不多所以这里横向的时候我们列表的高度就是我们给cell的高度,也就是我们的

    */

    _tableView= [[UIListTableViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,400)style:UITableViewStylePlain];

    _tableView.delegate=self;

    _tableView.dataSource=self;

    //横向竖向

    _tableView.direction=UITableViewDirectionTypeHorizontal;

    [self.viewaddSubview:_tableView];

    }

    -(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{

    return5;

    }

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

    return300;

    }

    -(UITableViewCell* )tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{

    staticNSString* idStr =@"cell_list";

    UIListViewCell* cell = [tableViewdequeueReusableCellWithIdentifier:idStr];

    if(cell ==nil) {

    cell = [[UIListViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:idStrtableView:_tableView];

    }

    cell.showSeparate=YES;//是否需要分割线

    cell.separateColor= [UIColorgreenColor];

    returncell;

    }

    需要在cell里面创建自己想要的控件的话直接移步到我们的updateView里面去创建就好了。

    下面代码链接附上:https://github.com/w1325087730/MYListView

    相关文章

      网友评论

          本文标题:横向列表(当然也可以纵向)(此文本人原创需要转载请注明出处。只做

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