IOS_學習筆記(Slider)
快速學習 Slider_滑桿 運用:
透過三個Slider滑桿的變化,來控制背景顏色!
這個是簡單的一個畫面的內容,所以首先我要知道我們需要建立什麼
需要 3 slider 與 原本的ViewController;有了這兩樣東西,
要讓視圖與控制器說話,所以要建立三個 IBAction ,告訴他說被改變了
要讓控制器與視圖說話,所以要建立三個IBOutlet,告訴他要改什麼
要讓視圖與控制器說話,所以要建立三個 IBAction ,告訴他說被改變了
要讓控制器與視圖說話,所以要建立三個IBOutlet,告訴他要改什麼
程式碼內容:
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UISlider *radSlider;
@property (weak, nonatomic) IBOutlet UISlider *greenSlider;
@property (weak, nonatomic) IBOutlet UISlider *blueSlider;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)rad:(id)sender {
[self background];
}
- (IBAction)green:(id)sender {
[self background];
}
- (IBAction)blue:(id)sender {
[self background];
}
-(void)background{
//拿到三個顏色
CGFloat rad = self.radSlider.value;
CGFloat green =self.greenSlider.value;
CGFloat blue = self.blueSlider.value;
UIColor * color = [UIColor colorWithRed:rad/255.0 green:green/255.0 blue:blue/255.0 alpha:1.0];
self.view.backgroundColor = color;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
留言
張貼留言