美文网首页
今天分享一些常见的代码块

今天分享一些常见的代码块

作者: JarodWang | 来源:发表于2018-04-08 16:57 被阅读22次

    代码块,小伙伴们应该都知道,自己定义一些繁杂又多又不想敲得代码块,使用起来就直接敲一到两个字回车就OK。酱紫方便了不知道多少对吧,在下技术一般大佬们看到自动忽略写得不好勿喷,多多指教。

    废话不多说进入正题

    选中自己想要添加的代码,然后鼠标别移动点击你当前选中的代码大概一到两秒鼠标变成小箭头的时候拖到这里


    1.afterGCD

    上面这个图是教各位怎么填写里面的东西

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<#delayInSeconds#> * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 

        <#code to be executed after a specified delay#>

    });

    上面的这张图是为了让大家看看怎么填写这些东西。方便使用下面的就不上图了直接上代码

    2.保证整个工程中只执行一次得OnceGCD

    staticdispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{

        <#code to be executed once#> 

    });

    3.MainGCD

    dispatch_async(dispatch_get_main_queue(), ^{

        <#code#> 

    });

    4.声明属性的assign

    /**

     <#Description#>

     */

    @property(nonatomic,assign)<#type#> <#value#>;


    5.声明属性的block

    /**

     <#Description#>

     */

    @property(nonatomic,copy) <#Block#> <#block#>;


    6.声明属性的代理

    /**

     <#Description#>

     */

    @property(nonatomic,weak)id<<#protocol#>> <#delegate#>;


    7.声明属性的strong

    /**

     <#Description#>

     */

    @property(nonatomic,strong) <#Class#> *<#object#>;


    8.cell当然需要在代理方法内部直接调用就可

    staticNSString *rid=<#rid#>; 

    <#Class#> *cell=[tableView dequeueReusableCellWithIdentifier:rid];

    if(cell==nil){


        cell=[[<#Class#> alloc] initWithStyle:UITableViewCellStyleDefault      reuseIdentifier:rid];


    }

    return cell;


    9.简单的按钮不带img的连带方法参上

    UIButton * <#object#> = [UIButton buttonWithType:UIButtonTypeCustom];

        <#object#> .backgroundColor = <#UIColor#>;

        <#object#> .titleLabel.font = <#UIFont#>;

        [<#object#>  setTitleColor:<#UIColor#> forState:UIControlStateNormal];

        <#object#> .userInteractionEnabled =YES;

        <#object#> .selected =NO;

        [ <#object#>  setTitle:<#value#> forState:UIControlStateNormal];

        [btn addTarget:selfaction:@Selector(<#methodName#>) forControlEvents:UIControlEventTouchUpInside];

        [<#UIView#> addSubView:<#Object#>];

        -(void)<#methodName#>:(<#btnClassName#> *)sender{ }


    10.简单的textField

      UITextField * <#object#> = [[UITextField alloc] init];

        <#object#>.font = <#UIFont#>;

        <#object#>.placeholder = <#placeholdStr#>;

        <#object#>.textColor = <#UIColor#>;

        <#object#>.backgroundColor = <#UIColor#>;

        [<#UIView#> addSubView:<#object#>];


    11.简单的label

     UILabel * <#object#> = [[UILabel alloc] init];

        <#object#> .backgroundColor = <#UIColor#>;

        <#object#> .textColor = <#UIColor#>;

        <#object#> .font = <#UIFont#>;

        <#object#> .text = <#NSSting#>;

        <#object#> .textAlignment = <#NSTextAlignment#>;

        [<#UIView#>  addSubView: <#object#> ];


    12.简单的img

     UIImageView * <#object#> = [[UIImageView alloc] init];

        <#object#>.image = [UIImage imageNamed:<#imgStr#>];

        [<#UIView#> addSubView:<#object#>];


    13.下拉刷新,当然注意这是refresh控件的

    /**

     下拉刷新

     */

    -(void)dropDownRefresh{


        __weak typeof(self) weakSelf = self;

        [<#object#> addLegendHeaderWithRefreshingBlock:^{

            int64_t delayInSeconds = <#value#>;

            dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);

            dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

                [weakSelf.<#object#>.legendHeader beginRefreshing];

                [weakSelf.<#object#>.legendHeader endRefreshing];

                    });

        }];

    }


    14.上拉加载

    /*

     上拉加载

     */

    -(void)pullUpLoad{

        self.page =0;

        __weak typeof(self) weakSelf = self;

        [<#object#> addLegendFooterWithRefreshingBlock:^{

            weakSelf.page +=1;

            int64_t delayInSeconds = <#value#>;

            dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);

            dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

            });

        }];

    }


    好啦暂时就分享到这里啦,本文原创转载请注明出处。另外本文仅做分享技术,不做商业用途。如有雷同尽情谅解。

    如果觉得可以点个赞~~你们的赞就是我的动力哈~!


    相关文章

      网友评论

          本文标题:今天分享一些常见的代码块

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