#import <UIKit/UIKit.h> @interface ViewController : UIViewController @property (weak, nonatomic) IBOutlet UISwitch *leftswitch; @property (weak, nonatomic) IBOutlet UISwitch *rightswitch; @property (weak, nonatomic) IBOutlet UILabel *label; - (IBAction)switchvaluechange:(id)sender; - (IBAction)slidervalue:(UISlider *)sender; - (IBAction)senderon:(id)sender; @end #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super 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. } //3 分段控制 - (IBAction)switchvaluechange:(id)sender { if(self.leftswitch.hidden ==YES) { self.rightswitch.hidden=NO; self.leftswitch.hidden=NO; }else{ self.leftswitch.hidden=YES; self.rightswitch.hidden=YES; } } //2 滑块控件设置 使用slider控件控制lable控件。 - (IBAction)slidervalue:(UISlider *)sender { // _label.text=[NSString stringWithFormat:@"%.f",sender.value]; //转化为字符串格式 int progressAsint = (int)(sender.value); NSString *newText = [[NSString alloc]initWithFormat:@"%d",progressAsint]; _label.text=newText; } //1 使两个按钮能够同步 - (IBAction)senderon:(id)sender { UISwitch *witchSwitch=(UISwitch *)sender; BOOL setting = witchSwitch.isOn; [self.leftswitch setOn:setting animated:YES]; [self.rightswitch setOn:setting animated:YES]; } @end
时间: 2024-10-10 23:13:05