22 amazing technologies developed by iOS, ios22
I have summed up 22 tips for iOS development based on my own practical development experience. In a very happy tone, I can easily solve all kinds of hard-hitting problems encountered during the development process.
1. What should I do if no Cell is displayed in TableView?
Similar to Figure 1, I don't want to display the empty ones below. It's easy to add "self. tableView. tableFooterView = [[UIView alloc] init];". After trying this sentence, it will look like Figure 2.
2. The custom leftBarbuttonItem left slide returned gesture is invalid. What should I do?
123456 |
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:img style:UIBarButtonItemStylePlain target:self action:@selector(onBack:)]; self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self; |
3. Why can't ScrollView be switched to the top of viewController?
1 |
self.automaticallyAdjustsScrollViewInsets = NO; |
4. What should I do if I want to throw my keyboard when writing a keyboard event?
- Buy a strong keyboard;
- IQKeyboardManager (available on GitHub) does not hurt your waist and legs after you use it.
5. Why is there a problem with my apps?
This is called KMCGeigerCounter. Go to GitHub and move it.
6. How can I adjust the separaLine position without creating a Cell?
1 |
_myTableView.separatorInset = UIEdgeInsetsMake(0, 100, 0, 0); |
7. How can I click self. view to collapse the keyboard? Do I need to add a tapGestures?
1234 |
- ( void )touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.view endEditing:YES]; } |
8. How to set the Default background image for each ViewController?
Use the base class.
9. I want to change the layoutAttributes added in xib in the code, but how can I find it using the code?
Nslayoutattribute can also be used to pull your constraints like a Button.
10. How can I hide the navigationbar when sliding like Safari?
1 |
navigationController.hidesBarsOnSwipe = Yes |
11. The title of the navigation bar's return key is so annoying. How can I make it disappear?
12 |
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault]; |
12. CoreData is so annoying to use. What should I do if the syntax is smelly and long?
MagicRecord
13. How does CollectionView implement the hovering header of tableview?
CSStickyHeaderFlowLayout
14. Can I use only one pan gesture to replace all directions of UISwipegesture?
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- ( 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 ; } } |
15. How can I make the image not deformed when stretching the image?
Method 1:
1 |
UIImage *image = [[UIImage imageNamed:@ "xxx" ] stretchableImageWithLeftCapWidth:10 topCapHeight:10]; |
Note: A developer reminds me that this application has been disabled. The current method is resizableImageWithCapInsets.
Method 2,
16. Why is there a better library when playing GIF videos?
FLAnimatedImage produced by FlipBoard is very suitable for you.
17. How can I add pull-up refresh in one sentence?
Use the SVPullToRefresh Library:
1234 |
[tableView addPullToRefreshWithActionHandler:^{ // prepend data to dataSource, insert cells at top of table view // call [tableView.pullToRefreshView stopAnimating] when done } position:SVPullToRefreshPositionBottom]; |
18. How can I change the Cell color in tableview to another color?
1 |
_mTableView.tintColor = [UIColor redColor]; |
19. Originally, my statusbar was lightcontent. Using UIImagePickerController will make my statusbar style black. What should I do?
1234 |
- ( void )navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:( BOOL )animated { [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } |
20. How can I make my navigationbar transparent instead of blurred?
1234 |
[self.navigationBar setBackgroundImage:[UIImage new ] forBarMetrics:UIBarMetricsDefault]; self.navigationBar.shadowImage = [UIImage new ]; self.navigationBar.translucent = YES; |
21. How can I change the color and position of uitextfield placeholder?
Inherit uitextfield and override this method:
1234 |
- ( void ) drawPlaceholderInRect:(CGRect)rect { [[UIColor blueColor] setFill]; [self.placeholder drawInRect:rect withFont:self.font lineBreakMode:UILineBreakModeTailTruncation alignment:self.textAlignment]; } |
22. Why do you know so many strange tricks?
Click Stack Overflow!