今天分享一些常見的代碼塊

代碼塊,小伙伴們應(yīng)該都知道,自己定義一些繁雜又多又不想敲得代碼塊,使用起來就直接敲一到兩個字回車就OK。醬紫方便了不知道多少對吧,在下技術(shù)一般大佬們看到自動忽略寫得不好勿噴,多多指教。

廢話不多說進入正題

選中自己想要添加的代碼,然后鼠標(biāo)別移動點擊你當(dāng)前選中的代碼大概一到兩秒鼠標(biāo)變成小箭頭的時候拖到這里


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.保證整個工程中只執(zhí)行一次得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當(dāng)然需要在代理方法內(nèi)部直接調(diào)用就可

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.下拉刷新,當(dāng)然注意這是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){

? ? ? ? });

? ? }];

}


好啦暫時就分享到這里啦,本文原創(chuàng)轉(zhuǎn)載請注明出處。另外本文僅做分享技術(shù),不做商業(yè)用途。如有雷同盡情諒解。

如果覺得可以點個贊~~你們的贊就是我的動力哈~!


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容