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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:22:51+00:00 2026-06-03T02:22:51+00:00

How can I make a method that takes in a float from 0-50, and

  • 0

How can I make a method that takes in a float from 0-50, and gives out a green color with uniform intensity?

So if the input value is 0, the color is black:

[UIColor colorWithRed:0 green:0 blue:0];

and if the input value is 50, the color is the max green color:

[UIColor colorWithRed:0 green:255.0/255.0 blue:0];

And so if the input factor is somewhere in the middle, then the color should be somewhere in the middle. So going from 0-50, it should go from the darkest green to the lightest green. Should be simple but I’m not sure what I’m missing:

//factor is a float from 0-50
UIColor *greenColor = [UIColor colorWithRed:0 green:factor/255.0 blue:0 alpha:1.0];

This code generates a green color, but doesn’t fluctuate much, so you only see about one shade of green.

  • 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-03T02:22:54+00:00Added an answer on June 3, 2026 at 2:22 am

    You need to scale the RGB max value (255) against your own max value (50). And all you need is fairly simple math:

    colorVal = 255 * x / 50
    

    where x is the intesity on the scale from 0 to 50. So:

    255 * 0  / 50 = 0 
    255 * 50 / 50 = 255
    255 * 25 / 50 = 128 (rounded up from 127.5)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i make an extension method that will work like this public static
I can make a variable's name from two variables' value: $a = 'tea'; $b
I've been trying to make a Jersey app that takes the following structure from
I have an action-method in a controller that takes requests coming from a variety
I have a method that takes a condition and item, from an array of
I would like to make a method that takes in a block, saves it
I have a method that takes a BOOL parameter and I want to make
How can I make google test fail if google mocked method is called more
Is there a way to make this method generic so I can return a
I can not locate the correct method to make the first item in a

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.