iOS 開發(fā)中簡(jiǎn)單實(shí)用的小技巧

技巧1:UIButton圖片與文字默認(rèn)是左右排列,如何實(shí)現(xiàn)右左排列?
解決技巧:

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

技巧2:設(shè)置導(dǎo)航欄透明,title與BarButtonItem不透明

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

self.navigationController.navigationBar.translucent = YES;
導(dǎo)航欄透明效果.png

技巧3:設(shè)置導(dǎo)航欄無邊框

self.navigationController.navigationBar.shadowImage = [UIImage new];
導(dǎo)航欄透明無邊框效果.png

技巧4: 隨視圖的滾動(dòng)導(dǎo)航欄隱藏與顯示(一句代碼即可)

self.navigationController.hidesBarsOnSwipe = Yes;
導(dǎo)航欄隱藏與顯示.gif

技巧5:簡(jiǎn)單好用的獲取當(dāng)前時(shí)間戳

   //時(shí)間戳
   time_t now;
   time(&now);
   NSLog(@"---%ld",now);
打印結(jié)果.png

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

 UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 100)];
 blueView.backgroundColor = [UIColor blueColor];
 [self.view addSubview: blueView];  
    /*設(shè)置圓角位置的枚舉參數(shù)
     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;
效果圖.png

技巧7: 加載UIWebView后禁止用戶復(fù)制剪切

// 控制器實(shí)現(xiàn)此方法
- (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:跳轉(zhuǎn)控制器隱藏tabbar一個(gè)一勞永逸的方法

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

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

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

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