iOS 代码块写法、合集(大大大大大大全,这个真是太有用了,贼爽)

iOS开发者应该知道,我们平时可以写一些常用的代码块,下次直接使用快捷键就能调用,不用重复编写。

写法如下:<#aaaa#>  

这样就可以像系统api一样填空了。

UIView *<#view#> = [[UIView alloc] init];
    <#view#>.frame = CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>);
    <#view#>.backgroundColor = [UIColor <#color#>];
    [<#self.view#> addSubview:<#view#>];

等等走......看下面...

下面这个是我平时积累的一些代码块,包含oc和swift两种语言,包含了大部分UI控件的创建等,使用非常简单。

这样积累有两个好处:

1、换电脑时不用重复编写这些代码块

2、两台电脑上一致的编码习惯

github地址是:https://github.com/ihoudf/DFCodeBlocks

用法:

1、下载,并复制CodeSnippets文件夹下的所有文件 
2、在mac的finder中前往文件夹地址:

~/Library/Developer/Xcode/UserData/CodeSnippets

3、将第一步复制的内容,粘贴到第二步的地址下,重启Xcode

 

具体用法:

包括Objective-C和swift两种语言,不断更新中...

ps:shortcut key即快捷键,命名方法是df+控件名小写。加df前缀可避免与控件的原代码提示冲突。

CodeBlockObjective-CSwiftshortcut key
@property✔️property
mark✔️✔️mark
todo✔️todo
fixme✔️fixme
warning✔️warning
UIViewControllerLifeCycle✔️✔️dfvclifecycle
UIView✔️✔️dfuiview
UIButton✔️✔️dfuibutton
UILabel✔️✔️dfuilabel
UIImageView✔️dfuiimageview
UITextField✔️dfuitextfield
UITextFieldDelegate✔️dfuitextfielddelegate
UITextView✔️dfuitextview
UITextViewDelegate✔️dftextviewdelegate
UIScrollView✔️dfuiscrollview
UIScrollViewDelegate✔️dfuiscrollviewdelegate
UITableView✔️dfuitableview
UITableViewDelegate✔️dfuitableviewdelegate
UITableViewDataSource✔️dfuitableviewdatasource
UIPickerView✔️dfuipickerview
UIPickerViewDelegate✔️dfuipickerviewdelegate
UIPickerViewDataSource✔️dfuipickerviewdatasource
UIWindow✔️dfuiwindow
UICollectionView✔️✔️dfuicollectionview
UICollectionViewDataSource✔️✔️dfuicollectionviewdatasource
UICollectionViewDelegate✔️✔️dfuicollectionviewdelegate
UICollectionViewDelegateFlowLayout✔️✔️dfuicollectionviewdelegateflowlayout
CGRect-CGFloat✔️dfcgrectfloat
CGRect-Double✔️dfcgrectdouble
CGRect-Int✔️dfcgrectint
UIEdgeInsets✔️dfuiedgeinsets

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值