UITextField textColor updates in iOS10, not in iOS 11
Asked Answered
M

2

6

My code fragment is very small:

self.textField.textColor = color

This is called in response to user interaction. It has been working for years. On my iOS 10 device it still works. On my iOS 11 device, the color does not change until I tap in the text field.

Bug? Feature? Workaround? Suggestions welcome.

Martica answered 15/10, 2017 at 0:36 Comment(4)
Provide more context. Show the whole method this line is in.Hierogram
Did you set a break point at this line with iOS 11? Make sure this called.Territorialism
I did show the whole method. The method is being called. At the risk of repeating myself, the exact same code works on iOS 10 (and has worked on 9, 8, & 7) but fails on iOS 11.Martica
Looping back in here, looks like this works as intended in iOS 12 (similarly to 10 and older). This seems like a bug in iOS 11.Ingrid
M
2

I can trigger the text color change to take effect by adding this line below the single line cited above:

self.textField.text = self.textField.text

However, given the facts above, it still looks to me like a bug outside of my code. Or, at least, a change of the implicit class contract.

Martica answered 15/10, 2017 at 16:48 Comment(0)
T
7

You might need to update/reset your UITextField text right after the color change:

self.textField.textColor = color
self.textField.text = "Hi! I've changed of color!!"

Andrew update, more practical stuff:

 self.textField.textColor = color
 self.textField.text =  self.textField.text
Tellurate answered 15/10, 2017 at 2:12 Comment(1)
In fact, adding the line self.textField.text = self.textField.text does fix the problem. Why didn't I think of that? The mystery remains, and from the symptoms I really do suspect it's a new bug/feature in the OS.Martica
M
2

I can trigger the text color change to take effect by adding this line below the single line cited above:

self.textField.text = self.textField.text

However, given the facts above, it still looks to me like a bug outside of my code. Or, at least, a change of the implicit class contract.

Martica answered 15/10, 2017 at 16:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.