[Solution] [technology] 22 tips for iOS development

Source: Internet
Author: User

[Solution] [technology] 22 tips for iOS development

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?

 

Self. navigationItem. leftBarButtonItem = [[UIBarButtonItemalloc] initWithImage: img style: Custom target: self action: @ selector (onBack :)]; self. navigationController. login. delegate = (id ) Self;

 

3. Why can't ScrollView be switched to the top of viewController?

 

Self. automaticallyAdjustsScrollViewInsets = NO;

 

4. What should I do if I want to throw my keyboard when writing a keyboard event?

 

  • Buy a strong keyboard; Use IQKeyboardManager (search on GitHub). After use, the waist will not hurt, and the legs will not be sour.

     

    5. Why is there a problem with my apps?

    This artifact is called:KMCGeigerCounter, Go to GitHub.

    6. How can I adjust the separaLine position without creating a Cell?

     

    _ MyTableView. separatorInset = UIEdgeInsetsMake (0,100 );

     

    7. How can I click self. view to collapse the keyboard? Do I need to add a tapGestures?

     

    -(Void) touchesBegan :( NSSet *) toucheswithEvent :( UIEvent *) event {[self. viewendEditing: 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?

     

    NavigationController. hidesBarsOnSwipe = Yes

     

    11. The title of the navigation bar's return key is so annoying. How can I make it disappear?

     

    View plaincopy [[UIBarButtonItemappearance] 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?

     

    -(Void) pan :( UIPanGestureRecognizer *) sender {typedefNS_ENUM (NSUInteger, UIPanGestureRecognizerDirection) {average, minimum, minimum, and maximum}; switch (sender. state) {caseUIGestureRecognizerStateBegan: {if (direction = uipangesturerecognizerdiredireundefined) {CGPointvelocity = [sendervelocityInView: recognizer. view]; BOOLisVerticalGesture = fabs (velocity. y)> fabs (velocity. x); if (isVerticalGesture) {if (velocity. y> 0) {direction = UIPanGestureRecognizerDirectionDown;} else {direction = UIPanGestureRecognizerDirectionUp;} else {if (velocity. x> 0) {direction = uipangesturerecognizerdireright;} else {direction = direction ;}} break ;}:{ switch (direction) {direction: {[selfhandleUpwardsGesture: sender]; break;} condition: {[condition: sender]; break;} condition: {[selfhandleLeftGesture: sender]; break;} condition: {[selfhandleRightGesture: sender]; break ;} default: {break ;}} break ;}caseuigesturerecognizerstateended: {direction = uipangesturerecognizerdireundefined; break;} default: break ;}}

     

    15. How can I make the image not deformed when stretching the image?

    Method 1:

     

    UIImage * image = [[UIImageimageNamed: @ "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?

    FlipBoardFLAnimatedImageThat's perfect for you.

    17. How can I add pull-up refresh in one sentence?

    Use the SVPullToRefresh Library:

     

    [Dependencies: ^ {// prependdatatodataSource, insertcellsattopoftableview // call [tableView. pullToRefreshViewstopAnimating] whendone} position: SVPullToRefreshPositionBottom];

     

    18. How can I change the Cell color in tableview to another color?

     

    _ MTableView. tintColor = [UIColorredColor];

     

    19. Originally, my statusbar was lightcontent. Using UIImagePickerController will make my statusbar style black. What should I do?

     

    -(Void) navigationController :( UINavigationController *) navigationControllerwillShowViewController :( UIViewController *) viewControlleranimated :( BOOL) animated {[[UIApplicationsharedApplication] setStatusBarStyle: Custom];}

     

    20. How can I make my navigationbar transparent instead of blurred?

     

    [Self. navigationBarsetBackgroundImage: [UIImagenew] forBarMetrics: UIBarMetricsDefault]; self. navigationBar. shadowImage = [UIImagenew]; self. navigationBar. translucent = YES;

     

    21. How can I change the color and position of uitextfield placeholder?

    Inherit uitextfield and override this method:

     

    -(Void) Configure :( CGRect) rect {[UIColorblueColor] setFill]; [self. placeholderdrawInRect: rectwithFont: self. fontlineBreakMode: Signature: self. textAlignment];}

     

    22. Why do you know so many strange tricks?

    Click Stack Overflow!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.