view.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property UILabel * red, * green, * blue, *hv;
@property UISlider * redSlider,*greenSlider,*blueSlider,*mainSlider;
@property UISwitch * mainSwitch,*mySwitch;
@property UIStepper * mainStepper;
@property NSMutableArray * mainArray;
@property UITextField *redText,*greenText,*blueText,*mainText,*stepText;
@property UIView * mainview;
@end
view.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
int x=20,y=280;
- (void)viewDidLoad {
[super viewDidLoad];
self.mainArray=[[NSMutableArray alloc]init];
[self label];
[self slider];
[self textField];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)label
{
self.red = [[UILabel alloc]initWithFrame:CGRectMake(20, 100, 30, 20)];
self.red.text=@"R";
[self.view addSubview:self.red];
self.green = [[UILabel alloc]initWithFrame:CGRectMake(20, 150, 30, 20)];
self.green.text=@"G";
[self.view addSubview:self.green];
self.blue = [[UILabel alloc]initWithFrame:CGRectMake(20, 200, 30, 20)];
self.blue.text=@"B";
[self.view addSubview:self.blue];
self.hv = [[UILabel alloc]initWithFrame:CGRectMake(100, 50, 50, 25)];
self.hv.text=@"H/V";
[self.view addSubview:self.hv];
}
-(void)slider
{
self.redSlider=[[UISlider alloc]initWithFrame:CGRectMake(60, 100, 100, 25)];
self.redSlider.minimumValue=0;
self.redSlider.maximumValue=255;
[self.redSlider addTarget:self action:@selector(rgbMethod:) forControlEvents:UIControlEventValueChanged];
[self.redSlider addTarget:self action:@selector(mainMethod) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.redSlider];
self.greenSlider=[[UISlider alloc]initWithFrame:CGRectMake(60, 150, 100, 25)];
self.greenSlider.minimumValue=0;
self.greenSlider.maximumValue=255;
[self.view addSubview:self.greenSlider];
[self.greenSlider addTarget:self action:@selector(rgbMethod:) forControlEvents:UIControlEventValueChanged];
[self.greenSlider addTarget:self action:@selector(mainMethod) forControlEvents:UIControlEventValueChanged];
self.blueSlider=[[UISlider alloc]initWithFrame:CGRectMake(60, 200, 100, 25)];
self.blueSlider.minimumValue=0;
self.blueSlider.maximumValue=255;
[self.blueSlider addTarget:self action:@selector(rgbMethod:) forControlEvents:UIControlEventValueChanged];
[self.blueSlider addTarget:self action:@selector(mainMethod) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.blueSlider];
self.mainSlider=[[UISlider alloc]initWithFrame:CGRectMake(60, 250, 100, 25)];
self.mainSlider.minimumValue=0;
self.mainSlider.maximumValue=10;
[self.mainSlider addTarget:self action:@selector(mainMethod) forControlEvents:UIControlEventValueChanged];
[self.mainSlider addTarget:self action:@selector(sliderValue) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.mainSlider];
self.mainSwitch=[[UISwitch alloc]initWithFrame:CGRectMake(180, 50, 0, 0)];
[self.view addSubview:self.mainSwitch];
[self.mainSwitch addTarget:self action:@selector(mainMethod) forControlEvents:UIControlEventValueChanged];
self.mainStepper=[[UIStepper alloc]initWithFrame:CGRectMake(280, 630, 0, 0)];
self.mainStepper.minimumValue=0;
self.mainStepper.maximumValue=10;
[self.mainStepper addTarget:self action:@selector(mainMethod) forControlEvents:UIControlEventValueChanged];
[self.mainStepper addTarget:self action:@selector(stepperValue) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.mainStepper];
}
-(void)textField
{
self.redText=[[UITextField alloc]initWithFrame:CGRectMake(170, 100, 50, 30)];
self.redText.borderStyle=UITextBorderStyleRoundedRect;
[self.view addSubview:self.redText];
self.greenText=[[UITextField alloc]initWithFrame:CGRectMake(170, 150, 50, 30)];
self.greenText.borderStyle=UITextBorderStyleRoundedRect;
[self.view addSubview:self.greenText];
self.blueText=[[UITextField alloc]initWithFrame:CGRectMake(170, 200, 50, 30)];
self.blueText.borderStyle=UITextBorderStyleRoundedRect;
[self.view addSubview:self.blueText];
self.mainText=[[UITextField alloc]initWithFrame:CGRectMake(170, 250, 50, 30)];
self.mainText.borderStyle=UITextBorderStyleRoundedRect;
[self.view addSubview:self.mainText];
self.mainview=[[UIView alloc]initWithFrame:CGRectMake(250, 100, 100, 150)];
self.mainview.backgroundColor=[UIColor blackColor];
[self.view addSubview:self.mainview];
self.stepText=[[UITextField alloc]initWithFrame:CGRectMake(240, 630, 40, 30)];
self.stepText.borderStyle=UITextBorderStyleBezel;
[self.view addSubview:self.stepText];
}
-(void)rgbMethod:(UISlider *)sender
{
self.redText.text=[NSString stringWithFormat:@"%i",(int)self.redSlider.value];
self.greenText.text=[NSString stringWithFormat:@"%i",(int)self.greenSlider.value];
self.blueText.text=[NSString stringWithFormat:@"%i",(int)self.blueSlider.value];
self.mainview.backgroundColor = [[UIColor alloc]initWithRed:self.redSlider.value/255.f green:self.greenSlider.value/255.f blue:self.blueSlider.value/255.f alpha:1.0];
self.mainText.text=[NSString stringWithFormat:@"%i",(int)self.mainSlider.value];
}
-(void)removeSwitch
{
for (int i=0; i<self.mainArray.count; i++)
{
UISwitch * mySwitch = [self.mainArray objectAtIndex:i];
[mySwitch removeFromSuperview];
x=20;
y=280;
}
}
-(void)mainMethod
{
if (self.mainSwitch.on==YES)
{
[self removeSwitch];
[self rgbMethod:nil];
self.stepText.text =[NSString stringWithFormat:@"%i",(int)self.mainStepper.value];
for (int i=0; i<self.mainStepper.value; i++)
{
self.mySwitch=[[UISwitch alloc]initWithFrame:CGRectMake(x, y, 0, 0)];
y=y+50;
if (y>600)
{
x=x+40;
y = 280;
}
self.mySwitch.thumbTintColor=[[UIColor alloc]initWithRed:self.redSlider.value/255.0 green:self.greenSlider.value/255.0 blue:self.blueSlider.value/255.0 alpha:1.0];
[self.view addSubview:self.mySwitch];
[self.mainArray addObject:self.mySwitch];
}
}
else if (self.mainSwitch.on==NO)
{
[self removeSwitch];
[self rgbMethod:nil];
self.stepText.text=[NSString stringWithFormat:@"%i",(int)self.mainStepper.value];
for (int i=0; i<(int)self.mainStepper.value; i++)
{
self.mySwitch=[[UISwitch alloc]initWithFrame:CGRectMake(x, y, 0, 0)];
x=x+40;
if (x>340) {
y=y+40;
x=20;
}
self.mySwitch.thumbTintColor=[[UIColor alloc]initWithRed:self.redSlider.value/255.0 green:self.greenSlider.value/255.0 blue:self.blueSlider.value/255.0 alpha:1.0];
[self.view addSubview:self.mySwitch];
[self.mainArray addObject:self.mySwitch];
}
}
}
-(void)sliderValue
{
[self.mainStepper setValue:self.mainSlider.value];
}
-(void)stepperValue
{
[self.mainSlider setValue:self.mainStepper.value];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Sign up here with your email
ConversionConversion EmoticonEmoticon