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

  • Home
  • SEARCH
  • 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 8171665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:31:51+00:00 2026-06-06T21:31:51+00:00

I am doing some exercises with delegate, but now I have a problem with

  • 0

I am doing some exercises with delegate, but now I have a problem with a UIView. This is my storyboardenter image description here

I want to change the color of the UIView with 3 UISliders. The range of UISliders is from 0 to 255.
And this is my code:

ColorField is the UIView custom class

ColorField.h

#import <UIKit/UIKit.h>

@protocol ColorFieldDelegate <NSObject>

-(NSArray *)giveMeColors;

@end

@interface ColorField : UIView

@property (nonatomic , weak) IBOutlet id<ColorFieldDelegate> delegate;

@end

ColorField.m

#import "ColorField.h"

@implementation ColorField
@synthesize delegate = _delegate;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
    NSArray *arrayOfColors = [self.delegate giveMeColors];
    int red = [[arrayOfColors objectAtIndex:0] intValue];
    int green = [[arrayOfColors objectAtIndex:1] intValue];
    int blue = [[arrayOfColors objectAtIndex:2] intValue];

    NSLog(@"Red --> %d" ,red);
    NSLog(@"Green --> %d" ,green);
    NSLog(@"Blue --> %d \n\n" ,blue);

    self.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0];

}


@end

ColorViewController.h

#import <UIKit/UIKit.h>
#import "ColorField.h"

@interface ColorViewController : UIViewController <ColorFieldDelegate> 

@property (nonatomic) IBOutlet ColorField *colorField;

@property (weak, nonatomic) IBOutlet UISlider *redSlider;

@property (weak, nonatomic) IBOutlet UISlider *greenSlider;

@property (weak, nonatomic) IBOutlet UISlider *blueSlider;

@end

ColorViewController.m

#import "ColorViewController.h"

@interface ColorViewController ()

@property (nonatomic) double redQuantity;
@property (nonatomic) double greenQuantity;
@property (nonatomic) double blueQuantity;

@end

@implementation ColorViewController

@synthesize colorField = _colorField;
@synthesize redSlider;
@synthesize greenSlider;
@synthesize blueSlider;

@synthesize redQuantity;
@synthesize blueQuantity;
@synthesize greenQuantity;

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.colorField setDelegate:self];
    [self.colorField setNeedsDisplay];

    self.redQuantity = 125.0;
    self.blueQuantity = 125.0;
    self.greenQuantity = 125.0;

    [self.colorField setNeedsDisplay];
    // Do any additional setup after loading the view, typically from a nib.
}

-(ColorField *)colorField
{
    if (_colorField == nil) {
        _colorField = [[ColorField alloc] init];
    }
    return _colorField;
}

- (void)viewDidUnload
{
    [self setColorField:nil];
    [self setRedSlider:nil];
    [self setGreenSlider:nil];
    [self setBlueSlider:nil];

    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

-(IBAction)changeRedQuantity:(UISlider *)sender
{
    //methods of UISliders
    self.redQuantity = [sender value];
    [self.colorField setNeedsDisplay];
}

-(IBAction)changeBlueQuantity:(UISlider *)sender
{
    self.blueQuantity = [sender value];
    [self.colorField setNeedsDisplay];
}

-(IBAction)changeGreenQuantity:(UISlider *)sender
{
    self.greenQuantity = [sender value];
    [self.colorField setNeedsDisplay];
}

-(NSArray *)giveMeColors
{
    NSNumber *redNumber = [NSNumber numberWithDouble:self.redQuantity];
    NSNumber *greenNumber = [NSNumber numberWithDouble:self.greenQuantity];
    NSNumber *blueNumber = [NSNumber numberWithDouble:self.blueQuantity];


    NSArray *array = [[NSArray alloc] initWithObjects:redNumber, greenNumber,blueNumber, nil];

    return array;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

BUT…this is the result: It show me only RED, GREEN and BLUE colors without gradation, for example: RGB (255,0,75) is THIS

enter image description here

and not THIS:

enter image description here

I don’t know with it can’t show me gradation…

Thanks!!

Marco Manzoni

  • 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-06T21:31:53+00:00Added an answer on June 6, 2026 at 9:31 pm

    You have to divide your slidervalues by 255.0.

    [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:1.0];

    colorWithRed only accepts values 0.0-1.0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing some exercises and I came across a problem. I have got DLL
I'm doing some SOAP exercises based on this example: http://www.vankouteren.eu/blog/2009/03/simple-php-soap-example/ But, I cannot get
I'am doing some exercises, but can't understand what is wrong. I have: Fraction+MathOps.h #import
I am doing some exercises in my object-oriented javascript book, I notice that this:
I started studying POSIX timers, so I started also doing some exercises, but I
I am doing some exercises from the book Thinking In Java . I have
Just started a tutorial in SQL for beginners. I'm doing some exercises now and
This might be trivial for some of you, but I have two screenshots from
Doing some testing but cannot fabricate debug environment so maybe someone can answer this.
I am doing some weekend coding exercises. I have a table that contains some

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.