UITextView not displaying text

Discussion in 'iOS Programming' started by forrestgrant, Oct 28, 2008.

  1. macrumors member

    Jun 24, 2008
    Here is my code
    		CGRect textFrame = CGRectMake(70, 25, 250, 30);
    		UITextView *textView = [[UITextView alloc] initWithFrame:textFrame];
    		[textView setTextColor:[UIColor whiteColor]];
    		[textView setFont:[UIFont systemFontOfSize:12]];
    		textView.text = @"Hello World";
    		[textField setBackgroundColor:[UIColor blackColor]];
    When I run the app... I can see the block where text should be... but no text written? Anyone else having this issue?
  2. macrumors regular

    Mar 24, 2008
    You never actually added the control to a view. Assuming this is in a view controller, you probably want to add a line like:

    [self.view addSubview:textView]
    Also you can use properties for those other items too, not just text:

    textView.font = [UIFont systemFontOfSize:12]
    Probably best to stay consistent between the 2 style of property assignment.
  3. thread starter macrumors member

    Jun 24, 2008
    Sorry I didn't add that line when pasting code, but I did add it to the view. The TextView appears (as a black box in the middle of the screen) But no text.

    To be sure I wasnt going crazy, if I change UITextView to UITextField the text displays just fine. I don't want to use UITextField because it does not allow multiple line text.

  4. macrumors 68030


    Sep 2, 2008
    FWIW, yes others on this forum and other forums have reported this. I haven't seen a clear explanation or solution.
  5. macrumors newbie

    Oct 27, 2008
    I had the same problem, my UITextView was positioned on UIScrollView outside of the visible screen and it didn't show text, when I put it on the visible part of the screen, the text is showed. I Guess it must be on the visible part of the screem.finally ended up using UILabel, works fine.
  6. macrumors 68040

    May 29, 2003
    Silly question but is this the 2.1version of the SDK.

    Just thought that I'd ask because Apple never notified me that 2.1 came out. I had to go pick it up myself.

    Sadly though it sounds like you ran into another bug in the SDK. Isn't that fun?


Share This Page