简体   繁体   中英

Text in UITextField shifts to left when pickerView comes up

I have a UITextField which on its rightview has a button. The textfield's input view is a pickerView. Now, I have hidden the cursor of the textField following here:

Hide the cursor of an UITextField

When I select the textField, the pickerView comes up. The first value in the pickerView is +1 . Everything is alright till here.

Now, when I select +34 from the pickerView, the text in the textField shifts to left and half of the plus is not visible in the left. After this, even if I select +1 , half of the plus is hidden in the left. I suspect it has to do with the amount of text area in the textField is getting increased because of the increase in size of text. Not sure though.

Note that when the pickerView goes down, the text in TextField aligns itself correctly.

What should I do to make sure the text does not get shifted to the left the whole thing remains visible?

Thanks.

Picker code

self.picker = UIPickerView()
self.picker.delegate = delegate
self.picker.dataSource = delegate
self.picker.showsSelectionIndicator = true

self.countriesSpinner = createPickerTextField([
    "width": width,
    "height": height,
    "top": top,
    "left": left
]) //This returns a text field
self.countriesSpinner.inputView = self.picker

Try this,

Execute your application in iOS simulator and Go To the DEBUG-> Color Blended layers and see what happens. You will be able to see there the reason why you can't see the complete text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM