使用slide修改UISlider背景顏色如下:
代碼,但是沒實現像連接圖片的效果:
@property (strong, nonatomic) IBOutlet UISlider *r;
@property (strong, nonatomic) IBOutlet UISlider *g;
@property (strong, nonatomic) IBOutlet UISlider *b;
-(void)blueSlider:(UISlider*)slider {
UIColor *newColor = [UIColor colorWithRed:_r.value green:_g.value blue:_b.value alpha:1];
_b.backgroundColor=newColor;
}
-(void)greenSlider:(UISlider*)slider {
UIColor *newColor = [UIColor colorWithRed:_r.value green:_g.value blue:_b.value alpha:1];
_g.backgroundColor=newColor;
}
-(void)redSlider:(UISlider*)slider {
UIColor *newColor = [UIColor colorWithRed:_r.value green:_g.value blue:_b.value alpha:1];
_r.backgroundColor=newColor;
}
我想要跟這一樣的。
你這個問題的關鍵在於:你在拿到UISlider的value後,使用[UIColor colorWithRed:green:blue:alpha:] 時並沒有將得到各顏色的值除以255.0
UIColor *newColor=[UIColor colorWithRed:_r.value/255.0f green:_g.value/255.0f blue:_b.value/255.0f alpha:1];