源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2020-12-20 03:05 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:iOS开发中简单实用的几个小技巧
[b]前言[/b] 本文记录了在iOS开发过程中所遇到的小知识点,以及一些技巧,下面话不多说,来看看详细的介绍。 [b]技巧1:UIButton图片与文字默认是左右排列,如何实现右左排列?[/b] [b]解决技巧:[/b]
button.transform = CGAffineTransformMakeScale(-1.0, 1.0);
button.titleLabel.transform = CGAffineTransformMakeScale(-1.0, 1.0);
button.imageView.transform = CGAffineTransformMakeScale(-1.0, 1.0);
[img]http://files.jb51.net/file_images/article/201611/20161121111608562.png?20161021111654[/img] [b]技巧2:设置导航栏透明,title与BarButtonItem不透明[/b]
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];

self.navigationController.navigationBar.translucent = YES;
[img]http://files.jb51.net/file_images/article/201611/20161121111733148.png?20161021111742[/img] [b]技巧3:设置导航栏无边框[/b]
self.navigationController.navigationBar.shadowImage = [UIImage new];
[img]http://files.jb51.net/file_images/article/201611/20161121111814105.png?20161021111823[/img] [b]技巧4: 随视图的滚动导航栏隐藏与显示(一句代码即可)[/b]
self.navigationController.hidesBarsOnSwipe = Yes;
[img]http://files.jb51.net/file_images/article/201611/20161121111856853.gif?2016102111195[/img] [b]技巧5:简单好用的获取当前时间戳[/b]
 //时间戳
 time_t now;
 time(&now);
 NSLog(@"---%ld",now);
[img]http://files.jb51.net/file_images/article/201611/20161121111939773.png?20161021111951[/img] [b]技巧6:只设置UIView的左上角和右上角的圆角 (四个圆角位置都可以选择)[/b]
 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;
[img]http://files.jb51.net/file_images/article/201611/20161121112023840.png?20161021112031[/img] [b]技巧7: 加载UIWebView后禁止用户复制剪切[/b]
// 控制器实现此方法
- (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];
}
[b]技巧8:跳转控制器隐藏tabbar一个一劳永逸的方法[/b]
// 创建一个Nav基类 重写pushViewController:方法 如下:
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {

 viewController.hidesBottomBarWhenPushed = YES;

 [super pushViewController:viewController animated:animated];

}
[b]总结[/b] 以上就是这篇文章的全部内容了,希望本文的这些小技巧对各位iOS开发者们能有所帮助,如果有疑问大家可以留言交流。小编还会陆续更新关于iOS相关技巧的文章,请继续关注编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部