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

大家可能都知道,在开发过程中我们总会遇到各种各样的小问题,有些小问题并不是十分容易解决。在此我就总结一下,我在开发中遇到的各种小问题,以及我的解决方法,也算是些小技巧吧,分享给大家,方便大家在iOS开发的时候能够参考借鉴,下面有需要的朋友一起来看看吧。

前言

本文记录了在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相关技巧的文章,请继续关注html中文网。

以上就是iOS开发中简单实用的几个小技巧的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 移动