Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7758737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:26:29+00:00 2026-06-01T13:26:29+00:00

I have some code that creates a bunch of UITextViews and puts them into

  • 0

I have some code that creates a bunch of UITextViews and puts them into another view. I change the backgroundColor to alternating colors and always set the textColor to black. They all work out fine, except for the last one that it creates. That one changes it’s textColor to whatever the backgroundColor of the text view is and then stops updating it’s UI.

If I check the value of textColor of the problematic in GDB, it is black, even though it isn’t displayed that way. Then I change it programmatically (push a button, loop through all the created text views and set the textColors all to purple), they all change except for the last one, who’s background color is the same as it’s text color. Again, when I check in GDB, the value of textColor, it is set at purple, even though this is not reflected on the screen.

WTF?!?!?! Any ideas? Could this just be a bug?

Here’s the code I’m using to add the UITextViews. I have UILabels in between so I can get centered text.

UIColor *evenColor = [self RGBColorR:90 G:95 B:90];
UIColor *oddColor = [self RGBColorR:70 G:75 B:70];

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    // Loop through adding the buttons.
    for (int i = 0; i < numberOfSections; i++) {
        // Add the label for the actual title of the level.
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, ((i * sectionHeight) - 1), self.levelLablesView.frame.size.width, 30)];
        [label setText:[levels objectAtIndex:i]];
        label.font = [UIFont fontWithName:@"Helvetica-Bold" size:24];
        [label setTextAlignment:UITextAlignmentCenter];
        [label setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
        if (i % 2 == 0) {
            // It's an even number.
            [label setBackgroundColor:evenColor];
        } else {
            // Its an odd number.
            [label setBackgroundColor:oddColor];
        }
        [self.levelLablesView addSubview:label];
        [label release];

        // Add a scrolling UITextView for the other stuff.
        UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, ((i * sectionHeight) + 24), self.levelLablesView.frame.size.width, (sectionHeight - 24))];
        [textView setText:[[[dictionary objectForKey:self.chosenCategory]
                            objectForKey:[levels objectAtIndex:i]]
                           objectForKey:@"Description"]];
        [textView setEditable:NO];
        [textView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
        if (i % 2 == 0) {
            // It's an even number.
            [textView setBackgroundColor:evenColor];
        } else {
            // Its an odd number.
            [textView setBackgroundColor:oddColor];
        }
        if (i == (numberOfSections-1)) {
            [textView setFrame:CGRectMake(0,((i * sectionHeight) + 24), self.levelLablesView.frame.size.width, ((sectionHeight - 24) + 2))];
        }
        textView.font = [UIFont systemFontOfSize:24];
        [textView setTextColor:[UIColor blackColor]];

        [self.levelLablesView addSubview:textView];
        [textView release];
    }

}

Edit: In case anyone is wondering, I don’t set the text color anywhere else in the program by accident. I did a find for “textColor” and the only matches I get are irrelevant.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:26:31+00:00Added an answer on June 1, 2026 at 1:26 pm

    I fixed this with hacks. I think that this is a bug.

    Originally, I added a UIView filled with the background color that I wanted behind the UITextView.

    However, I discovered that scrolling the UITextView also changes the background color to the color that it is set as.
    So I added a BOOL alreadyScrolled; to my .h, added a call to [self scrollLevelLabelsViews] in viewDidAppear: (which first checks to make sure it hasn’t alreadyScrolled because viewDidAppear: can get called multiple times if a modal view is presented, for example), and added the following method to scroll the views. I was also having an issue with the last text view not displaying text correctly but neglecting to create it until the alreadyScrolled method after the view has appeared makes it display fine.

    The following are the methods I created to scroll the text views down and back up. Just change levelLablesView to the view that contains your textViews, add the method calls and variables I explained in the last paragraph, and it should work for you.

    - (void)scrollLevelLabelsViewsBackUp{
    
        // Scroll all UITextViews in levelLabelsView to the top.
        for (UIView *view in self.levelLablesView.subviews) {
            if ([view isKindOfClass:[UITextView class]]) {
                UITextView *textView = (UITextView *)view;
                [textView scrollRangeToVisible:NSMakeRange(1, 1)];
            }
        }
        alreadyScrolled = YES;
    
    }
    
    - (void)scrollLevelLabelsViews{
    
       /* Setup last UITextView that displays weirdly if it is set up with the rest of them.
        * ...
        */
    
        // Scroll all UITextViews in levelLabelsView to the bottom.
        for (UIView *view in self.levelLablesView.subviews) {
            if ([view isKindOfClass:[UITextView class]]) {
                UITextView *textView = (UITextView *)view;
                [textView scrollRangeToVisible:NSMakeRange([[textView text] length] - 2, 1)];
            }
        }
    
        // In .8 seconds, scroll them back up.
        [NSTimer scheduledTimerWithTimeInterval:.8 target:self selector:@selector(scrollLevelLabelsViewsBackUp) userInfo:nil repeats:NO];
    
    }
    

    This is also just a cool effect even if you’re not having this problem as it lets the user know that there is more text that they can’t see and that the text view is scrollable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that creates a new site in SharePoint. Upon browsing to
I have some code that creates a Process instance and later starts it. There's
I have some code that dynamically creates a new button through JavaScript that when
I have some javascript code that creates an img tag with a mouseover callback,
I have some Javascript code that creates 2 arrays: One for Product Category and
I have some code on my PHP powered site that creates a random hash
I have some code which I did not originally create that uses _beginthreadex and
we have some C++ code that we need to create a make file in.
I have some code that gives a user id to a utility that then
i have a bunch of Console.WriteLines in my code that I can observe at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.