iOS開發中簡單實用的幾個小技巧_IOS

來源:互聯網
上載者:User

前言

本文記錄了在iOS開發過程中所遇到的小知識點,以及一些技巧,下面話不多說,來看看詳細的介紹。

技巧1:UIButton圖片與文字預設是左右排列,如何?右左排列?

解決技巧:

button.transform = CGAffineTransformMakeScale(-1.0, 1.0);button.titleLabel.transform = CGAffineTransformMakeScale(-1.0, 1.0);button.imageView.transform = CGAffineTransformMakeScale(-1.0, 1.0);


技巧2:設定導覽列透明,title與BarButtonItem不透明

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];self.navigationController.navigationBar.translucent = YES;

技巧3:設定導覽列無邊框

self.navigationController.navigationBar.shadowImage = [UIImage new];


技巧4: 隨視圖的滾動導覽列隱藏與顯示(一句代碼即可)

self.navigationController.hidesBarsOnSwipe = Yes;


技巧5:簡單好用的擷取目前時間戳

 //時間戳記 time_t now; time(&now); NSLog(@"---%ld",now);

技巧6:只設定UIView的左上方和右上方的圓角 (四個圓角位置都可以選擇)

 UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 100)]; blueView.backgroundColor = [UIColor blueColor]; [self.view addSubview: blueView];  /*設定圓角位置的枚舉參數  UIRectCornerTopLeft  = 1 << 0,  UIRectCornerTopRight = 1 << 1,  UIRectCornerBottomLeft = 1 << 2,  UIRectCornerBottomRight = 1 << 3,  UIRectCornerAllCorners = ~0UL  */ UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:blueView.bounds byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) cornerRadii:CGSizeMake(20.0, 20.0)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = blueView.bounds; maskLayer.path = maskPath.CGPath; blueView.layer.mask = maskLayer;


技巧7: 載入UIWebView後禁止使用者複製剪下

// 控制器實現此方法- (BOOL)canPerformAction:(SEL)action withSender:(id)sender{ if (action == @selector(copy:) ||  action == @selector(paste:)||  action == @selector(cut:)) {  return NO; } return [super canPerformAction:action withSender:sender];}

技巧8:跳轉控制器隱藏tabbar一個一勞永逸的方法

// 建立一個Nav基類 重寫pushViewController:方法 如下:-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { viewController.hidesBottomBarWhenPushed = YES; [super pushViewController:viewController animated:animated];}

總結

以上就是這篇文章的全部內容了,希望本文的這些小技巧對各位iOS開發人員們能有所協助,如果有疑問大家可以留言交流。小編還會陸續更新關於iOS相關技巧的文章,請繼續關注云棲社區。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.