Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView text color not getting set when disabled selectable property

Setup :

I have simple textview added in storyboard based view, with outlet taken in viewcontroller's .m file. I am setting text using it. e.g [_textViewOne setText:@"Test text"];. I am using Xcode 6.1, compiling with iOS 8.1.

Scenario :

I wanted to make UITextView non touchable, just like UILabel ( i am using UITextView instead of UILabel because my text may be 1 or 2 line and UILabel aligns text at vertically center of view for 1 line and for 2 lines it starts from top left, i want it to start from top left in both cases which is easily achievable by textview ).

To make it non touchable first i disabled selectable property of it from Storyboard and tried to run application. After unchecking selectable property my text view's text not using the colour i set for it ( i have set red colour ) and it is using default black colour.

enter image description here

If i check selectable, text colour follows whatever i set in interface builder.

Issues :

  1. Why unchecking of selectable property from interface builder doesn't follow whatever textcolor i set for textview.

  2. One more thing i noticed, if i uncheck selectable property from interface builder and tried to set it programmatically like _textViewOne.selectable = YES; then also TextView doesn't follow whatever textcolor i set in interface builder, only checking that property from interface builder works. ( Tried with clean build, restarting xcode also )

( I know i should just make textview's user interaction disabled to make it non touchable, but i accidentally unchecked selectable and it took my time to figure out what was happening, so just wanted to know was i doing something wrong or this is some kind of issue or this is correct behaviour of this control. )

like image 668
Aditya Deshmane Avatar asked Dec 28 '14 13:12

Aditya Deshmane


2 Answers

Looks like this bug was fixed on iOS 10.

However, I was very surprised when I saw this bug in our bugtracker and cannot reproduce on iOS 10, but successfully reproduced it on iOS9.

Solution in my case was to write it in code in this order:

textView.textColor = UIColor.red
textView.isSelectable = false

P.S.

textViewOne.userInteractionEnabled = false is not works for me, because I want textview to be scrollable, but without selection option.

like image 127
Pavlo Shadov Avatar answered Nov 15 '22 00:11

Pavlo Shadov


For disabling interaction with a textView (making it non touchable) you can use:

_textViewOne.userInteractionEnabled = NO;
like image 20
Boaz Saragossi Avatar answered Nov 15 '22 00:11

Boaz Saragossi