0

I've got a UITextView with a small text in it. It displays correctly with black text on white background. However, when I want to change the text colour to a colour other than black, the text position changes (as if there was an empty line added at the beginning of the text).

With no colour change or with textView.textColor = [UIColor blackColor]; :

correct displaying with black colour

When I change to another colour, here textView.textColor = [UIColor blueColor]; :

incorrect displaying with any other colour

The code line I've given really is the only code element that changes, and even if the colours in the background and the text are different, this is because they are generated randomly, in a complete other part of my code. The content of the text NEVER had any influence on the display before, and when I change the text colour it ALWAYS looks like in the 2nd picture.

I am stunned by this behaviour, as textColor shouldn't be modifying anything else than the font colour, should it ? Plus the fact that when I change to blackColor, no weird behaviour.

Thank you for your help...

Cal
  • 188
  • 3
  • 12
  • What do you mean by "no weirt behaviour"? Does it change the position back as seen in the first screenshot or does it stay at the wrong position but changes to black? – Hermann Klecker Jul 11 '12 at 14:00
  • And yes. Changes to the textColor property shoudl not change much but the colour. I am afraid that you must have made some other changes to the view or view hierarchy. Apparently you have not yet realized what that is. Go and look for it. You may want to NSLog the lable (or whatever view it is) object directly. It describes itself very well including text, colour and font (I think), position and size respectively its frame. – Hermann Klecker Jul 11 '12 at 14:02
  • @HermannKlecker2: **without touching anything else**, if I comment this particular code line, it switches to correct behaviour (1st picture), and if I uncomment it then it behaves like in the 2nd picture. With NSLog, no font/colour info but frame is exactly the same in both cases. – Cal Jul 11 '12 at 15:17
  • I think both text is different..That would be a bigger one from the first one.I think so. – Dinesh Raja Jul 11 '12 at 15:56
  • @R.A and @Hermann: I've edited my question so that you understand why I'm sure that the line `textView.textColor = [UIColor blueColor];` is the source of the problem. – Cal Jul 12 '12 at 12:12

1 Answers1

1

"the different colours in the background are generated somewhere else" means Where do you exactly change the colors?

You are changing some thing like

a)autoresizing the views (or)

b)Aligning text in that view (or)

c)Frame size of your textView can be smaller than the font size of your textview (or)

d)your text would be longer than actual size of the frame.

I would like to ask you one question. Why do you use UITextView instead of UILabel?? I'm asking because textview will bring the scrollview, when the text is longer than your frame size.Probably that would be your problem I hope..

Dinesh Raja
  • 8,501
  • 5
  • 42
  • 81
  • No autoresizing, no aligning, the frame size of my textView is big enough and anyway not changing (I tried increasing the textView width but it didn't solve the problem). Indeed, with a UILabel there seems to be no problem, but I cannot copy/paste the content of the label, can I ? Well, if I get no further explanation I'll probably end up using a UILabel, thank you for the tip... – Cal Jul 11 '12 at 15:08
  • Of course you can copy and paste from your UIlabel..I m sure. – Dinesh Raja Jul 11 '12 at 15:54
  • Well, apparently you can't copy from a UILabel if you use it raw : http://stackoverflow.com/questions/1246198/show-iphone-cut-copy-paste-menu-on-uilabel. And I can't manage to make the textView scroll, but I can have the kind of magnifying glass appear and see the whole text. – Cal Jul 12 '12 at 12:05
  • Check @zoul answer in that question..I just did it and i works for him – Dinesh Raja Jul 13 '12 at 11:46