iOS开发小技巧(一)

分享一下容易忽视的一些小技巧

1.让tableView不显示空的单元格:

self.tableView.tableFooterView = [UIView alloc] init];

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

  self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]

                                         initWithImage:img

                                         style:UIBarButtonItemStylePlain

                                         target:self

                                         action:@selector(onBack:)];

self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;

3.ScrollView莫名其妙不能在viewController划到顶怎么办?

self.automaticallyAdjustsScrollViewInsets = NO;

4.隐藏导航条navigationBar

self.navigationController.hidesBarsOnSwipe = YES;

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

[self.navigationBar setBackgroundImage:[UIImage new]

                         forBarMetrics:UIBarMetricsDefault];

self.navigationBar.shadowImage = [UIImage new];

self.navigationBar.translucent = YES;

6.怎么改变uitextfield placeholder的颜色和位置?

- (void) drawPlaceholderInRect:(CGRect)rect {

    [[UIColor blueColor] setFill];

    [self.placeholder drawInRect:rect withFont:self.font lineBreakMode:UILineBreakModeTailTruncation alignment:self.textAlignment];

}

7.当拖动tableView时,键盘回收

    self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;

8.button 的title左右上下对齐

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;

    [button setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 18, 0)];

9.改变视图的透明度,不改变子视图

 self.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.5];

你可能感兴趣的:(iOS开发小技巧(一))