iOS 开发的技巧

来源:互联网 发布:淘宝店铺年销售额查询 编辑:程序博客网 时间:2024/06/05 15:40

1.TableView 不显示内容的 cell 怎么办?

添加代码”self.tableView.tableFooterView=[[UIView alloc]init]”

2.自定义了 leftBarbuttonItem 轻扫手势返回失效了怎么办?

   self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithImage:img style:UIBarButtonItemStylePlain target:self action:@selector(back)];    self.navigationController.interactivePopGestureRecognizer.delegate=(id<UIGestureRecognizerDelegate>)self;

3.ScrollView 莫名其妙的不能在 ViewController 滑到顶怎么办?

self.automaticallyAdjustsScrollViewInsets=NO;

4.键盘事件总是要每一个响应者都写一遍很麻烦则么办?

IQKeyboardManager去查—–

5.怎么看我的 App 为什么卡顿?

KMCGeigerCounter 去查——-

6.怎么在不新建一个 Cell 的情况下调整 separaLine 的位置?在一个 cell 上添加 分割线

tableView.separatorInset=UIEdgeInsetsMake(0,100,0,0);

7.怎么点击 self.view 让键盘收起

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{    [self.view endEditing:YES];}

8.想在代码里改在 xib 里添加的 layoutAttributes, 怎么找到它?

约束也可以拖拽

9.怎么像 Safari 一样滑动的时候隐藏navigationBar?

navigationController.hidesBarsOnSwipe=YES;

10.导航栏带的返回键的 title 太讨厌了,怎么让它消失?

[[UIBarButtonItem appearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];

11.CoreData 用起来好烦,语法又臭又长怎么办?

MagicRecord去查—–

12.CollectionView 怎么实现 tableView 那种悬停的 headerView?

CSStickyHeaderFlowLayout去查——

13.拉伸图片的时候怎么才能让图片不变形?

    UIImage *image=[[UIImage imageNamed:@"xxx"]stretchableImageWithLeftCapWidth:10 topCapHeight:10];

这个方法是拉伸图片的方法 自己多试试就知道怎么用了

14.怎么解决播放 GIF的时候很卡的情况?

FLAnimatedImage去查—

15.怎么添加上拉刷新?

SVPullToRefresh去查—–

16.么把 tableView 里的 Cell的小对勾改成别的颜色?

tableView.tintColor=[UIColor greenColor];

17.笨啦我的 statusBar 是 lightContent 的,结果用 UIImagePickerController,会导致我的 statusBar 变成黑色,怎么办?

-(UIStatusBarStyle)preferredStatusBarStyle{    return UIStatusBarStyleLightContent;}

18.怎么把我的 navigationBar 弄成透明的而不是带模糊的效果?

    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];    self.navigationController.navigationBar.shadowImage=image;    self.navigationController.navigationBar.translucent=YES;

18.怎么改变 UITextField plaseholder 的颜色和位置?
继承 UITextField(子类化一个 UITextField) 重写下面的方法:

-(void)drawPlaceholderInRect:(CGRect)rect{    [[UIColor blueColor]setFill];    [self.placeholder drawInRect:rect withAttributes:@{NSFontAttributeName:@"Helvetica",NSForegroundColorAttributeName:@"defaultParagraphStyle"}];}
0 0