Skip to content

Instantly share code, notes, and snippets.

@20m61
Created December 3, 2012 10:20
Show Gist options
  • Save 20m61/4194068 to your computer and use it in GitHub Desktop.
Save 20m61/4194068 to your computer and use it in GitHub Desktop.
背景色を変えるのにスライダーを使った
//
// ViewController.h
// 121203
//
// Created by changhwi on 12/12/03.
// Copyright (c) 2012年 changhwi. All rights reserved.
//
#import <UIKit/UIKit.h>
//RGB,Alpha値
float valueR = 0.5;
float valueG = 0.5;
float valueB = 0.5;
float valueAlpha = 1.;
float chengeColor = 0.2;
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIView *viewFirst;
@end
//
// ViewController.m
// 121203
//
// Created by changhwi on 12/12/03.
// Copyright (c) 2012年 changhwi. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self viewUpdate];
int center = self.view.frame.size.width / 2;
int bottom = self.view.frame.size.height;
int bottomMargin = 0;
int buttonWidth = self.view.frame.size.height / 5 * 4;
int buttonHeight = 0;
int buttonMargin = 0;
//270度回転
CGAffineTransform trans = CGAffineTransformMakeRotation(M_PI * 270 / 180.0f);
#pragma mark - sliderR
UISlider *sliderR = [[UISlider alloc]
initWithFrame:CGRectMake(center - buttonWidth / 2 - center / 2, bottom / 2, buttonWidth, buttonHeight)];
sliderR.value = 0.5;
sliderR.minimumValue = 0.0;
sliderR.maximumValue = 1.0;
sliderR.continuous = YES;
sliderR.transform = trans;
[sliderR addTarget:self
action:@selector(sliderRValueChanged:)
forControlEvents:UIControlEventValueChanged];
[self.view addSubview:sliderR];
#pragma mark - sliderG
UISlider *sliderG = [[UISlider alloc]
initWithFrame:CGRectMake(center - buttonWidth / 2, bottom / 2, buttonWidth, buttonHeight)];
sliderG.value = 0.5;
sliderG.minimumValue = 0.0;
sliderG.maximumValue = 1.0;
sliderG.continuous = YES;
sliderG.transform = trans;
[sliderG addTarget:self
action:@selector(sliderGValueChanged:)
forControlEvents:UIControlEventValueChanged];
[self.view addSubview:sliderG];
#pragma mark - sliderB
UISlider *sliderB = [[UISlider alloc]
initWithFrame:CGRectMake(center - buttonWidth / 2 + center / 2, bottom / 2, buttonWidth, buttonHeight)];
sliderB.value = 0.5;
sliderB.minimumValue = 0.0;
sliderB.maximumValue = 1.0;
sliderB.continuous = YES;
sliderB.transform = trans;
[sliderB addTarget:self
action:@selector(sliderBValueChanged:)
forControlEvents:UIControlEventValueChanged];
[self.view addSubview:sliderB];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - viewUpdate
- (void)viewUpdate{
self.view.backgroundColor = [UIColor colorWithRed:valueR green:valueG blue:valueB alpha:valueAlpha ];
}
#pragma mark - buttonRUpdateMethod
- (void)sliderRValueChanged:(id)sender
{
UISlider *slValueR = sender;
valueR = slValueR.value;
// スライダーの値をログに記述
NSLog(@"スライダーの値:%f", slValueR.value);
[self viewUpdate];
}
#pragma mark - buttonGUpdateMethod
- (void)sliderGValueChanged:(id)sender
{
UISlider *slValueG = sender;
valueG = slValueG.value;
// スライダーの値をログに記述
NSLog(@"スライダーの値:%f", slValueG.value);
[self viewUpdate];
}
#pragma mark - buttonBUpdateMethod
- (void)sliderBValueChanged:(id)sender
{
UISlider *slValueB = sender;
valueB = slValueB.value;
// スライダーの値をログに記述
NSLog(@"スライダーの値:%f", slValueB.value);
[self viewUpdate];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment