關(guān)于Xcode的代碼塊抬吟,我感覺(jué)應(yīng)該是這個(gè)編譯器里最好用的部分的榴芳,用的好的話對(duì)你開發(fā)的速度是成十倍百倍的效率提升。期間也轉(zhuǎn)用過(guò)AppCode焚刺,最終還是用回Xcode,轉(zhuǎn)回來(lái)又兩個(gè)主要原因门烂,首先還是被流暢度給打敗了乳愉,其次雖然我也覺(jué)得idea他們公司編譯器的快捷鍵也很強(qiáng)大確實(shí)也很好用,但是我還是喜歡這個(gè)代碼塊屯远,對(duì)我個(gè)人來(lái)說(shuō)簡(jiǎn)直就是神器蔓姚。
很早之前也研究過(guò)AppCode有沒(méi)有這樣可以高度自定義的代碼塊功能,但是沒(méi)有研究出來(lái)慨丐,如果有知道的大神請(qǐng)?jiān)谠u(píng)論區(qū)教一教我??坡脐。。房揭。
??將近3年的Xcode的使用經(jīng)驗(yàn)备闲,我自己多少也總結(jié)了不少自己常用的代碼塊晌端,請(qǐng)將目光向下移動(dòng)。
-
快速創(chuàng)建數(shù)組屬性
快捷鍵:
ht_array
輸出:
@property (nonatomic,copy) NSArray * <#name#>;
-
快速創(chuàng)建基本數(shù)據(jù)類型屬性
快捷鍵:
ht_assign
輸出:
@property (nonatomic,assign) <#class#> <#name#>;
-
快速創(chuàng)建字符屬性
快捷鍵:
ht_string
輸出:
@property (nonatomic,copy) NSString * <#name#>;
-
快速創(chuàng)建強(qiáng)引用屬性
快捷鍵:
ht_strong
輸出:
@property (nonatomic,strong) <#class#> * <#name#>;
-
快速創(chuàng)建弱引用屬性
快捷鍵:
ht_weak
輸出:
@property (nonatomic,weak) <#class#> * <#name#>;
-
快速創(chuàng)建弱引用指針
快捷鍵:
ht_weak_self
輸出:
__weak typeof(self) __self = self;
-
快速創(chuàng)建代碼塊屬性
快捷鍵:
ht_block
輸出:
@property (nonatomic, copy) void(^<#name#>)();
-
截取系統(tǒng)側(cè)滑手勢(shì)[備注:有些特殊情況下需要禁用掉系統(tǒng)的側(cè)滑功能恬砂,但是有的時(shí)候直接禁用nav的側(cè)滑手勢(shì)在某些可能下會(huì)造成系統(tǒng)的假死(我遇到過(guò)很多次)咧纠,所以,這是我經(jīng)常使用的方法]泻骤,這個(gè)方法就是通過(guò)添加手勢(shì)來(lái)截?cái)嘞到y(tǒng)的手勢(shì)惧盹。
快捷鍵:
ht_cehua
輸出:
UIScreenEdgePanGestureRecognizer *ges = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:nil];
ges.edges = UIRectEdgeLeft;// 指定左邊緣滑動(dòng)
[self.view addGestureRecognizer:ges];
-
快速創(chuàng)建按鈕
快捷鍵:
ht_creatButton
輸出:
UIButton *<#button#> = [UIButton buttonWithType:UIButtonTypeCustom];
[<#button#> setTitleColor:[MyColor pg_mainTitleColor] forState:UIControlStateNormal];
<#button#>.titleLabel.font = [UIFont systemFontOfSize:<#size#>];
[<#button#> setTitle:@"" forState:UIControlStateNormal];
<#button#>.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
-
鍵盤監(jiān)聽
快捷鍵:
ht_keyboarderObeserver
輸出:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; - (void)keyboardWillShow:(NSNotification *)notification { //獲取鍵盤的高度 NSDictionary *userInfo = [notification userInfo]; NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; CGRect keyboardRect = [value CGRectValue]; int height = keyboardRect.size.height; } //當(dāng)鍵退出 - (void)keyboardWillHide:(NSNotification *)notification { //獲取鍵盤的高度 NSDictionary *userInfo = [notification userInfo]; NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; CGRect keyboardRect = [value CGRectValue]; int height = keyboardRect.size.height; }
-
快速創(chuàng)建按鈕
快捷鍵:
ht_creatTableViewHeaderBtn
輸出:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setTitleColor:<#Color#> forState:UIControlStateNormal]; [button setBackgroundColor:<#Color#>]; button.titleLabel.font = [UIFont systemFontOfSize:<#FontSize#>]; [button setTitle:@"" forState:UIControlStateNormal]; button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [button setContentEdgeInsets:UIEdgeInsetsMake(0, 15, 0, 0)]; return button;
-
快速創(chuàng)建tableview
快捷鍵:
ht_creatTableView
輸出:
UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; tableView.delegate = self; tableView.dataSource = self; tableView.bounces = YES; tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; tableView.backgroundColor = <#Color#>; tableView.estimatedRowHeight = 0; tableView.estimatedSectionHeaderHeight = 0; tableView.estimatedSectionFooterHeight = 0; self.tableView = tableView; [self.view addSubview:tableView]; [tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.navigationView.mas_bottom); make.left.bottom.right.equalTo(self.view); }];
-
快速創(chuàng)建tableview代理方法
快捷鍵:
ht_creatTableView_delegate
輸出:
#pragma -mark- tableView delegate datasuoce
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return <#count#>;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
return <#cell#>;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return <#count#>;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
-
快速創(chuàng)建collectionView
快捷鍵:
ht_creatCollectionView
輸出:
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
flowLayout.headerReferenceSize = CGSizeMake(<#width#>, <#height#>);
flowLayout.footerReferenceSize = CGSizeMake(<#width#>, <#height#>);
UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flowLayout];
collectionView.delegate = self;
collectionView.dataSource = self;
collectionView.backgroundColor = [UIColor whiteColor];
[collectionView registerNib:[UINib nibWithNibName:@"" bundle:nil] forCellWithReuseIdentifier:@"cell"];
[collectionView registerNib:[UINib nibWithNibName:@"" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head"];
[collectionView registerNib:[UINib nibWithNibName:@"" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];
[self.view addSubview:collectionView];
self.flowLayout = flowLayout;
self.collectionview = collectionView;
[collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.navigationView.mas_bottom);
make.left.bottom.right.equalTo(self.view);
}];
-
快速創(chuàng)建collectiongView代理
快捷鍵:
ht_creatCollectionView_delegate
輸出:
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return <#count#>;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return <#count#>;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
return nil;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;
{
//如果是頭視圖
if ([kind isEqualToString:UICollectionElementKindSectionHeader])
{
return nil;
}
else if ([kind isEqualToString:UICollectionElementKindSectionFooter])
{
return nil;
}
return nil;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath;
{
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(<#width#>, <#height#>);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(0, 0, 0, 0);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return 0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return 0;
}