Gocy015 Gocy015 - 1 month ago 49
Objective-C Question

UITextField Chinese character moves down when editing in iOS 10

The environment that I'm using is Xcode8 and iOS10 .

What did i do:

In IB , drag an

UITextField
into my main view ,add some constraints to place the textfield in the right place , select the textfield's border style to none, at last, type some text to make the UITextField resize in storyboard ,like below:
TextField in storyboard

In order to see what's going on , i also make the textfield to draw its boundary by adding this in
viewDidLoad
:
self.textField.layer.borderWidth = 1;


Build and run , it looks good on device:

enter image description here

The Problem

However,if i try to edit the textfield (when the textfield becomes first responder) , the text moves down :

enter image description here

This issue occurs only when setting the Textfield's border style to none and the text contains Chinese characters , does anyone has a clue of what's happening here ?

Answer

Same issue to me. I use UIAlertView contain UITextField, I fix it by setting textField.clearButtonMode = UITextFieldViewModeWhileEditing;That's ok.

Another method is : subclass UITextField, rewrite:

  • (CGRect)textRectForBounds:(CGRect)bounds {

    return CGRectInset(bounds, 2, 1);

}

  • (CGRect)editingRectForBounds:(CGRect)bounds { return CGRectInset(bounds, 2, 1);

}