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 8998979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:06:54+00:00 2026-06-16T00:06:54+00:00

This is more of a math question but I’m just not having any luck.

  • 0

This is more of a math question but I’m just not having any luck. Basically Ive got the code below to change cell colors depending on their row equivalent in the colors array. It all works very well but I would like it so that I could somehow cut off the bottom end of the brightness spectrum so that I never end up with anything say, below 0.2. Any suggestions on how to solve this would be appreciated.

-(IBAction)reloadTable {
    float arrayCount = [masterListArray count];
    float increment = (1.0 / arrayCount);
    NSMutableArray *tempColor = [[NSMutableArray alloc]init];
    colors = [[NSMutableArray alloc]init];

    for (float brightness = 0.0; brightness < 1.0; brightness += increment) {
        UIColor *color = [UIColor colorWithHue:50.0f/255.0f
                                    saturation:1.0
                                    brightness:brightness
                                         alpha:1.0];
       [tempColor addObject:color];
       NSLog(@"brightness: %f", brightness);
    }

    colors = [[tempColor reverseObjectEnumerator] allObjects];
    [self.tableView reloadData];
}
  • 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-16T00:06:55+00:00Added an answer on June 16, 2026 at 12:06 am

    You can use some extra variables to make sure you always end up between 1.0 and the bottom end. In the below code we use the number of cells to iterate through (better practice than what you had before) and start with brightness 1.0 and end at your bottom end. Also no need to use tempColors.

    -(IBAction)reloadTable {
    
        float arrayCount = [masterListArray count];
        float bottomEnd = 0.2;
        float brightnessRange = 1.0 - bottomEnd;
        float increment = (brightnessRange / arrayCount);
    
        colors = [NSMutableArray array];
    
        for (int i = 0; i < arrayCount; i++) {
            // We start with light and go darker per cell.
            float brightness = bottomEnd + (brightnessRange - i * increment); 
            UIColor *color = [UIColor colorWithHue:50.0f/255.0f
                                        saturation:1.0
                                        brightness:brightness
                                             alpha:1.0];
            [colors addObject:color];
            NSLog(@"brightness: %f", brightness);
        }
    
        [self.tableView reloadData];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK. This might be more of a math question but here goes. I have
I guess this is a math question and not a programming question, but what
This may be a more math focused question, but wanted to ask here because
This may be a math question more than a programming question, but we'll see.
Not sure if I should've posted this on math.stackexchange instead, but it includes more
I think this is more like Math question rather than programming but since I'm
I apologize as I don't know whether this is more of a math question
First of all this is more of a math question than it is a
This is more of a programming problem than a technical question but since it
This is less an HTML, CANVAS question and more of a general math question.

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.