UITextField won't return to center alignment after edit

UITextField set to horizontal center alignment. Entering edit would move the text to the left. However, the text does not return to center after editing. In "Did End On Exit" handler, textAlignment was indeed set to NSTextAlignment. Calling setTextAlignment to NSTextAlignmentCenter again in "Did End On Exit" event handler did not move the text to center. calling setNeedsDisplay,setNeedLayout etc didn't make any difference.


Happened in Simulator and on real iPad 2 Air.


XCode V7.3.1

IOS 9.0


Any help would be appreciated.

Check the details in UITextField doc.


But I think that you should set allowsEditingTextAttributes to true in order to change the text attributes.

Thanks for the suggestion. I went back to XCode yesterday and the problem mysteriously disappeared. I didn't have a chance to work on the program between posting the question and yesterday and so I didn't make any changes at all. Maybe the act of restarting XCode corrected the problem.

UITextField won't return to center alignment after edit
 
 
Q