IOS development Note 11: forms, keyboard occlusion, floating point price formatting, UIPickerView content style modification, View Debugging, debugger

Source: Internet
Author: User

IOS development Note 11: forms, keyboard occlusion, floating point price formatting, UIPickerView content style modification, View Debugging, debugger
1. Form and keyboard occlusion

The application scenario is that a collectionView has multiple textfields and textviews for users to fill in information.

When there are few input items, the method is rough. When didSelectItemAtIndexPath is used, write down the gap between collectionViewCell and the bottom of the screen, and compare it with the keyboard height. Adjust the contentOffset of collectionView according to the actual situation, however, this method does not work when many input items exist. You need to calculate more collectionViewCell distance from the bottom of the screen, which is prone to errors.

Text Programming Guide for iOS-Managing the KeyboardThis section describes the solution. Because Masonry is used, it is not convenient to adjust the frame directly.

(1) when selecting an input item, write down the indexPath to facilitate subsequent collectionView slide operations. Note that userInteractionEnabled of textField and textView in collectionViewCell is set to NO, it becomes the first responder only when the user is selected. (2) obtain the keyboard height, adjust collectionView Based on the keyboard height, and slide to the position of the target cel (3) restore the initial constraints of collectonView when the keyboard is hidden. 2. format the floating point price.

There is an application scenario where the price is precisely displayed to 2 decimal places and the decimal point is 0, for example, 99.00 is displayed as 99, and 99.90 is displayed as 99.9 yuan, directly Using the stringWithFormat method of NSString to convert the display of the decimal point does not meet the requirements. First, the string containing two decimal places is obtained. Then, we can remove the 0 of the decimal part after special processing ,:

Refer:IOS floating point number is removed from the decimal point 0.00 and the price format is displayed.

3. Modify the UIPickerView content style

When you use UIPickerView, the content displayed by default may not meet the requirements. You often need to modify the content style, such as the text size, UIPickerView itself provides such a proxy method for us to customize

4. View Debugging

Xcode provides some view debugging tools. debugging and analysis are useful when you draw an interface, especially when the interface is incorrectly displayed. You can find these gadgets in the Debug-View Debugging tool bar of Xcode, including screen snapshots, hierarchical View analysis, and View frame.

(1) As the name implies, a screen snapshot captures the current status of the screen and is saved as a photo.

(2) Capture View Hierarchy helps check the constraints and View levels of the interface.

(3) Show View Frames/Show Alignment Rectangles is used to display the frame or Alignment rectangle of the View element. Generally, the show View Frames option is used, at last, there will be an extra rectangle around each UI element on the screen, representing its size. The layout of some elements is abnormal, which helps to locate the constraints of the UI element.

 

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.