Question

I have a UITextField that is an address bar for a web browser. When the user loads a page and the page finishes loading, I want the textfield to change the text color to dark gray. It does this just fine. However, when the user edits the textfield again I want the text color to change back to black. Using the -(BOOL) textFieldShouldBeginEditing:(UITextField *)textField method I try to change the color by using addressBar.textColor = [UIColor blackColor]; but it does not work. What am I doing wrong?

Was it helpful?

Solution

Is textFieldShouldBeginEditing: getting called? If not, you need to set your text field's delegate to the class that implements this method.

Is addressBar set to your text field at the time the delegate method is being called?

Try using NSLog to debug.

OTHER TIPS

Solution that might work better on iOS 7 and up.

If your UITextView contains text that is detected to be address/phone number/etc, you've got to set tintColor to change text colour of detected items, like this:

self.tvPhone.tintColor = [UIColor blueColor];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top