顏色範例程式碼
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UISlider *red;
@property (weak, nonatomic) IBOutlet UISlider *blue;
@property (weak, nonatomic) IBOutlet UISlider *green;
@property (weak, nonatomic) IBOutlet UILabel *redLabel;
@property (weak, nonatomic) IBOutlet UILabel *blueLabel;
@property (weak, nonatomic) IBOutlet UILabel *greenLabel;
@end
@implementation ViewController
- (IBAction)colorChange:(UISlider *)sender {
float red=self.red.value;
float blue=self.blue.value;
float green=self.green.value;
_redLabel.text=[NSString stringWithFormat:@"Red:%.0f",red];
_blueLabel.text=[NSString stringWithFormat:@"Blue:%.0f",blue];
_greenLabel.text=[NSString stringWithFormat:@"Green:%.0f",green];
UIColor * color = [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:1];
self.view.backgroundColor=color;
}
@end
Comments
Post a Comment