關(guān)于Xcode的代碼塊

關(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;
    }

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市瞪讼,隨后出現(xiàn)的幾起案子钧椰,更是在濱河造成了極大的恐慌,老刑警劉巖符欠,帶你破解...
    沈念sama閱讀 222,729評(píng)論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件嫡霞,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡希柿,警方通過(guò)查閱死者的電腦和手機(jī)诊沪,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,226評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)曾撤,“玉大人端姚,你說(shuō)我怎么就攤上這事〖废ぃ” “怎么了渐裸?”我有些...
    開封第一講書人閱讀 169,461評(píng)論 0 362
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)装悲。 經(jīng)常有香客問(wèn)我昏鹃,道長(zhǎng),這世上最難降的妖魔是什么诀诊? 我笑而不...
    開封第一講書人閱讀 60,135評(píng)論 1 300
  • 正文 為了忘掉前任洞渤,我火速辦了婚禮,結(jié)果婚禮上属瓣,老公的妹妹穿的比我還像新娘载迄。我一直安慰自己,他們只是感情好抡蛙,可當(dāng)我...
    茶點(diǎn)故事閱讀 69,130評(píng)論 6 398
  • 文/花漫 我一把揭開白布护昧。 她就那樣靜靜地躺著,像睡著了一般溜畅。 火紅的嫁衣襯著肌膚如雪捏卓。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,736評(píng)論 1 312
  • 那天慈格,我揣著相機(jī)與錄音怠晴,去河邊找鬼。 笑死浴捆,一個(gè)胖子當(dāng)著我的面吹牛蒜田,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播选泻,決...
    沈念sama閱讀 41,179評(píng)論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼冲粤,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了页眯?” 一聲冷哼從身側(cè)響起梯捕,我...
    開封第一講書人閱讀 40,124評(píng)論 0 277
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎窝撵,沒(méi)想到半個(gè)月后傀顾,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,657評(píng)論 1 320
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡碌奉,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,723評(píng)論 3 342
  • 正文 我和宋清朗相戀三年短曾,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片赐劣。...
    茶點(diǎn)故事閱讀 40,872評(píng)論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡嫉拐,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出魁兼,到底是詐尸還是另有隱情婉徘,我是刑警寧澤,帶...
    沈念sama閱讀 36,533評(píng)論 5 351
  • 正文 年R本政府宣布咐汞,位于F島的核電站判哥,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏碉考。R本人自食惡果不足惜塌计,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,213評(píng)論 3 336
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望侯谁。 院中可真熱鬧锌仅,春花似錦、人聲如沸墙贱。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,700評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)惨撇。三九已至伊脓,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間魁衙,已是汗流浹背报腔。 一陣腳步聲響...
    開封第一講書人閱讀 33,819評(píng)論 1 274
  • 我被黑心中介騙來(lái)泰國(guó)打工株搔, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人纯蛾。 一個(gè)月前我還...
    沈念sama閱讀 49,304評(píng)論 3 379
  • 正文 我出身青樓纤房,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親翻诉。 傳聞我的和親對(duì)象是個(gè)殘疾皇子炮姨,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,876評(píng)論 2 361