Created
November 30, 2012 10:05
-
-
Save 20m61/4174911 to your computer and use it in GitHub Desktop.
buttonWithType+tintColorでボタンの背景色を変える
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.m | |
// 121130 | |
// | |
// Created by changhwi on 12/11/30. | |
// Copyright (c) 2012年 changhwi. All rights reserved. | |
// | |
#import "ViewController.h" | |
@interface ViewController() | |
@end | |
#pragma clang diagnostic ignored "-Wunused-value" | |
@implementation ViewController | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
float valueR = 0.0; | |
float valueG = 1.0; | |
float valueB = 1.0; | |
float valueA = 1.0; | |
UIButton *buttonRPlus = [UIButton buttonWithType:100]; | |
[buttonRPlus setTitle:@"R+" forState:UIControlStateNormal]; | |
//x, y, w, h | |
buttonRPlus.frame = CGRectMake(20, 350, 70, 50); | |
buttonRPlus.tintColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0]; | |
[self.view addSubview:buttonRPlus]; | |
UIButton *buttonRMinus = [UIButton buttonWithType:UIButtonTypeRoundedRect]; | |
[buttonRMinus setTitle:@"R-" forState:UIControlStateNormal]; | |
[buttonRMinus sizeToFit]; | |
//x, y, w, h | |
buttonRMinus.frame = CGRectMake(20, 410, 70, 50); | |
[self.view addSubview:buttonRMinus]; | |
UIButton *buttonGPlus = [UIButton buttonWithType:UIButtonTypeRoundedRect]; | |
[buttonGPlus setTitle:@"R+" forState:UIControlStateNormal]; | |
[buttonGPlus sizeToFit]; | |
//x, y, w, h | |
buttonGPlus.frame = CGRectMake(100, 350, 70, 50); | |
[self.view addSubview:buttonGPlus]; | |
UIButton *buttonGMinus = [UIButton buttonWithType:UIButtonTypeRoundedRect]; | |
[buttonGMinus setTitle:@"G-" forState:UIControlStateNormal]; | |
[buttonGMinus sizeToFit]; | |
//x, y, w, h | |
buttonGMinus.frame = CGRectMake(100, 410, 70, 50); | |
[self.view addSubview:buttonGMinus]; | |
UIButton *buttonBPlus = [UIButton buttonWithType:UIButtonTypeRoundedRect]; | |
[buttonBPlus setTitle:@"R+" forState:UIControlStateNormal]; | |
[buttonBPlus sizeToFit]; | |
//x, y, w, h | |
buttonBPlus.frame = CGRectMake(180, 350, 70, 50); | |
[self.view addSubview:buttonBPlus]; | |
UIButton *buttonBMinus = [UIButton buttonWithType:UIButtonTypeRoundedRect]; | |
[buttonBMinus setTitle:@"G-" forState:UIControlStateNormal]; | |
[buttonBMinus sizeToFit]; | |
//x, y, w, h | |
buttonBMinus.frame = CGRectMake(180, 410, 70, 50); | |
[self.view addSubview:buttonBMinus]; | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
- (void)viewUpdate{ | |
if (valueR >= 1.0 || valueG >= 1.0 || valueB >= 1.0) { | |
[UIView | |
animateWithDuration:0.1 | |
animations:^{self.view.backgroundColor = | |
[UIColor colorWithRed:valueR green:valueG blue:valueG alpha:1.0];}]; | |
} | |
else{ | |
[UIView | |
animateWithDuration:0.1 | |
animations:^{self.view.backgroundColor = | |
[UIColor colorWithRed:valueR green:1.0 blue:1.0 alpha:1.0];}]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment