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.
If i check selectable
, text colour follows whatever i set in interface builder.
Issues :
Why unchecking of selectable
property from interface builder doesn't follow whatever textcolor i set for textview.
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. )
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.
For disabling interaction with a textView (making it non touchable) you can use:
_textViewOne.userInteractionEnabled = NO;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With