zoukankan      html  css  js  c++  java
  • iOS 持续更新 开发中的一些小问题和技巧1

    1.IOS8 设置TableView Separatorinset 分割线从边框顶端开始  
     
    -(void)viewDidLayoutSubviews
    {
        if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
            [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
        }
        
        if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
            [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
        }
    }
     
    -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
            [cell setSeparatorInset:UIEdgeInsetsZero];
        }
        
        if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
            [cell setLayoutMargins:UIEdgeInsetsZero];
        }
    }

     2.push的时候的一些不可不用的细节

    CartConfirmOrderViewController *viewController = [[CartConfirmOrderViewController alloc] init];  //   这是要push过去的自定义controller
            viewController.hidesBottomBarWhenPushed = YES;  //  我push过去的页面不需要tabbar,这个方法完美解决
            viewController.arrayWithPrice = self.arrayWithPrice;  //  需要传点数据给push过去的页面,轻轻松松

     3.关于tableViewcell 分割线不完整

    如果只是简单的初始化一个cell,可能可以满足大部分需求。但是直接初始化的tableviewcell的左边的分割线是默认15像素的距左,如果需求是分割线等cell宽,如果是通过取消分割线然后再设置控件去做假效果当然可以实现,但其实原生方法可以取消这个讨厌的15像素

    分两步。直接贴上以下代码即可

    -(void)viewDidLayoutSubviews
    {
        if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
            [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
        }
        
        if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
            [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
        }
    }
    
    -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
            [cell setSeparatorInset:UIEdgeInsetsZero];
        }
        
        if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
            [cell setLayoutMargins:UIEdgeInsetsZero];
        }
    }
    

    另外:

    设置footer可以取消多余的cell的哦,但是我觉得并不优美,推荐下面的写法

    -(void)setExtraCellLineHidden: (UITableView *)tableView {  //  随便自定义一个方法,self调用即可
        UIView *view = [UIView new];
        view.backgroundColor = [UIColor clearColor];
        [tableView setTableFooterView:view];  //   其实道理是一样的,但是这样个人觉得更漂亮,比较好标注
    }
    

    4. 关于导航条

    现在需求是导航条透明,navigationBar设置一张透明的背景图应该是比较好的选择。但是这样做导航条下面会出现一条黑色的细线,以下方法取消

     //去掉导航栏下部的黑色素线
        if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]){
            NSArray *list = self.navigationController.navigationBar.subviews;
            for (id obj in list) {
                if ([obj isKindOfClass:[UIImageView class]]) {
                    UIImageView *imageView=(UIImageView *)obj;
                    imageView.hidden=YES;
                }
            }
        }
    
  • 相关阅读:
    angularjs中的指令
    git笔记
    webpack.config.js
    webpack开发react常用插件和依赖
    angularjs中的分页指令
    angularjs中的排序和过滤
    react学习
    gulp学习
    Javascript 判断变量类型的陷阱 与 正确的处理方式
    Fn.bind.apply() 解决 new 操作符不能用与 apply 或 call 同时使用
  • 原文地址:https://www.cnblogs.com/mdurant/p/5259054.html
Copyright © 2011-2022 走看看