#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *sliderLabel;
@property (weak, nonatomic) IBOutlet UISlider *mySlider;
@property (weak, nonatomic) IBOutlet UISwitch *leftSlider;
@property (weak, nonatomic) IBOutlet UISwitch *rightSlider;
- (IBAction)sliderChanged:(id)sender;
- (IBAction)switchChanged:(id)sender;
@end
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize mySlider,sliderLabel;
@synthesize leftSlider,rightSlider;
- (void)viewDidLoad {
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)mySlider:(id)sender {
}
- (IBAction)sliderChanged:(id)sender {
UISlider *thisSlider = (UISlider *)sender;
int progressInt = (int)roundf(thisSlider.value);
sliderLabel.text = [NSString stringWithFormat:@"%i",progressInt];
BOOL isSwitchOn = NO;
if (progressInt > thisSlider.maximumValue/2){
isSwitchOn = YES;
}
[leftSlider setOn:isSwitchOn animated:YES];
[rightSlider setOn:!isSwitchOn animated:YES];
}
- (IBAction)switchChanged:(id)sender {
if ([sender isKindOfClass:[UISwitch class]]){
UISwitch *thisSwitch = (UISwitch *)sender;
BOOL setting = thisSwitch.isOn;
[leftSlider setOn:setting animated:YES];
[rightSlider setOn:setting animated:YES];
}
}
@end