iOS开发的21个技巧

2016-04-26  本文已影响40人  pzliOS

开发的21个奇葩技巧

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

使用IQKeyboardManager(GitHub上可搜索)

KMCGeigerCounter ,快去GitHub上搬运吧

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

[self.view endEditing:YES];

使用基类啊

像拉Button一样地拉你的约束,nslayoutattribute也是可以拉线的。

navigationController.hidesBarsOnSwipe = Yes
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)                                                    forBarMetrics:UIBarMetricsDefault];

MagicRecord

CSStickyHeaderFlowLayout

(void)pan:(UIPanGestureRecognizer *)sender
 {
 typedef NS_ENUM(NSUInteger, UIPanGestureRecognizerDirection) {
    UIPanGestureRecognizerDirectionUndefined,
    UIPanGestureRecognizerDirectionUp,
    UIPanGestureRecognizerDirectionDown,
    UIPanGestureRecognizerDirectionLeft,
    UIPanGestureRecognizerDirectionRight
};
 static UIPanGestureRecognizerDirection direction = UIPanGestureRecognizerDirectionUndefined;
switch (sender.state) {
     case UIGestureRecognizerStateBegan: {
        if (direction == UIPanGestureRecognizerDirectionUndefined) {
             CGPoint velocity = [sender velocityInView:recognizer.view];
             BOOL isVerticalGesture = fabs(velocity.y) > fabs(velocity.x);
             if (isVerticalGesture) {
                if (velocity.y > 0) {
                    direction = UIPanGestureRecognizerDirectionDown;
                } else {
                    direction = UIPanGestureRecognizerDirectionUp;
                }
            }
             else {
                 if (velocity.x > 0) {
                    direction = UIPanGestureRecognizerDirectionRight;
                 } else {
                     direction = UIPanGestureRecognizerDirectionLeft;
                 }
             }
         }
         break;
     }
     case UIGestureRecognizerStateChanged: {
         switch (direction) {
             case UIPanGestureRecognizerDirectionUp: {
                 [self handleUpwardsGesture:sender];
                 break;
             }
             case UIPanGestureRecognizerDirectionDown: {
                 [self handleDownwardsGesture:sender];
                 break;
             }
             case UIPanGestureRecognizerDirectionLeft: {
                 [self handleLeftGesture:sender];
                 break;
             }
             case UIPanGestureRecognizerDirectionRight: {
                 [self handleRightGesture:sender];
                 break;
             }
            default: {
                 break;
             }
         }
         break;
     }
     case UIGestureRecognizerStateEnded: {
         direction = UIPanGestureRecognizerDirectionUndefined;
         break;
     }
     default:
         break;
 }
 }
UIImage *image = [[UIImage imageNamed:@"xxx"] stretchableImageWithLeftCapWidth:10 topCapHeight:10];

注:有开发者提醒这个已经弃用,现在的方法叫

resizableImageWithCapInsets。

FlipBoard出品的FLAnimatedImage太适合你了。

 [tableView addPullToRefreshWithActionHandler:^{
// prepend data to dataSource, insert cells at top of table view
// call [tableView.pullToRefreshView stopAnimating] when done
 } position:SVPullToRefreshPositionBottom];
_mTableView.tintColor = [UIColor redColor];
 (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
[self.navigationBar setBackgroundImage:[UIImage new]
                          forBarMetrics:UIBarMetricsDefault];
 self.navigationBar.shadowImage = [UIImage new];
 self.navigationBar.translucent = YES;
```
- 怎么改变uitextfield placeholder的颜色和位置?
继承uitextfield,重写这个方法:  
```
 (void) drawPlaceholderInRect:(CGRect)rect {
     [[UIColor blueColor] setFill];
     [self.placeholder drawInRect:rect withFont:self.font lineBreakMode:UILineBreakModeTailTruncation alignment:self.textAlignment];
 }
  ```
上一篇 下一篇

猜你喜欢

热点阅读