iOS开发小技巧(收集及个人)

1. 隐藏UITableView多余cell的分割线

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

2. 取消UINavigationController自带的返回字样

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

3. 滑动时隐藏navigation

self.navigationController.hidesBarsOnSwipe=YES;

4. 页面跳转是隐藏tabBar

TwoViewController *twoVC = [[TwoViewController alloc] init];

twoVC.hidesBottomBarWhenPushed =YES;

5. ScrollView不能滑到顶

self.automaticallyAdjustsScrollViewInsets=NO;

6. 按钮点击发光效果

button.showsTouchWhenHighlighted =YES;

7.长按手势只执行一次

if(sender.state == UIGestureRecognizerState)

8. 隐藏状态栏

- (BOOL)prefersStatusBarHidden{

returnYES;

}

9. 在使用view的缩放的时候,layer.border.width随着view的放大,会出现锯齿化的问题。

self.layer.allowsEdgeAntialiasing = YES;

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

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

11. 怎么在不新建一个Cell的情况下调整separaLine的位置?

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

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

MagicRecord

13. 本来我的statusbar是lightcontent的,结果用UIImagePickerController会导致我的statusbar的样式变成黑色,怎么办?

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

}

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

[self.navigationBar setBackgroundImage:[UIImage new]

forBarMetrics:UIBarMetricsDefault];

self.navigationBar.shadowImage = [UIImage new];

self.navigationBar.translucent = YES;

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

继承uitextfield,重写这个方法

- (void) drawPlaceholderInRect:(CGRect)rect {

[[UIColor blueColor] setFill];

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

}

16. 遇到了二进制颜色,怎么办呢?

#define UIColorFromRGBValue(rgbValue)                [UIColor colorWithRed:((CGFloat)(rgbValue & 0xFF0000) << 16) / 255 green:((CGFloat)(rgbValue & 0xFF00) << 8) / 255 blue:((CGFloat)(rgbValue) << 0xFF) / 255 alpha:1.0] 

你可能感兴趣的:(iOS开发小技巧(收集及个人))