iOS开发移动开发iOS学习开发

iOS 开发中简单实用的小技巧

2016-11-17  本文已影响100人  RichardZhao

技巧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);
效果.png

技巧2:设置导航栏透明,title与BarButtonItem不透明

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

self.navigationController.navigationBar.translucent = YES;
导航栏透明效果.png

技巧3:设置导航栏无边框

self.navigationController.navigationBar.shadowImage = [UIImage new];
导航栏透明无边框效果.png

技巧4: 随视图的滚动导航栏隐藏与显示(一句代码即可)

self.navigationController.hidesBarsOnSwipe = Yes;
导航栏隐藏与显示.gif

技巧5:简单好用的获取当前时间戳

   //时间戳
   time_t now;
   time(&now);
   NSLog(@"---%ld",now);
打印结果.png

技巧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;
效果图.png

技巧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];
    
}

上一篇下一篇

猜你喜欢

热点阅读