ios - UITextField does not automatically resize width to fit contents until resignFirstResponder is called? -


i'm not sure why happening, have static cell, consists of uitextfield. inputview uipickerview , inputaccessorytype uitoolbar.

i created so:

var repeat_array: [string] = []  override func viewdidload() {     super.viewdidload()      repeat_array.append("no cycle")     repeat_array.append("semi-monthly")      toolbar.barstyle = uibarstyle.default     toolbar.istranslucent = true     toolbar.sizetofit()      let donebutton = uibarbuttonitem(title: "done", style: .done, target: self, action: #selector(viewcontroller.dismisspicker(_:) ) )      let spacebutton = uibarbuttonitem(barbuttonsystemitem: uibarbuttonsystemitem.flexiblespace, target: nil, action: nil)      toolbar.setitems([spacebutton, donebutton], animated: false)     toolbar.isuserinteractionenabled = true      createcell() }  func numberofcomponents(in pickerview: uipickerview) -> int {     return 1 }  func pickerview(_ pickerview: uipickerview, titleforrow row: int, forcomponent component: int) -> string? {     return repeat_array[row] }  func pickerview(_ pickerview: uipickerview, didselectrow row: int, incomponent component: int) {     textfield.text = repeat_array[row] }  func pickerview(_ pickerview: uipickerview, numberofrowsincomponent component: int) -> int {     return repeat_array.count }  func dismisspicker(_ sender: uibarbuttonitem) {     textfield.resignfirstresponder() }  func createcell() {     textfield.text = "no cycle"     textfield.delegate = self      let pickerview: uipickerview = uipickerview()      pickerview.delegate = self     pickerview.datasource = self      textfield.inputview = pickerview      textfield.inputaccessoryview = toolbar } 

and how set in storyboard:

enter image description here

when viewcontroller loaded, textfield.text value no cycle, fits fine. however, when scroll uipickerview select 2nd row, i.e. semi-monthly, text gets cut-off so:

enter image description here

it's not until hit done uibarbuttonitem call textfield.resignfirstresponder width of textfield automatically exands fit contents of string semi-monthly so: enter image description here

i don't quite understand why happening?

set 'leading, trailing, top , fixed height constraint' textfield , issue solved ! if can't set leading , trailing both should set fixed width.


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -