Objective-C Learning Notes - UIStepper
Base Attributes:
value;
minimumValue;
maximumValue;
stepValue;
Other Control Attributes:
continuous;//是否持续触发 UIControlEventValueChanged 事件
autorepeat;//按住的时候是否持续触发,默认是 YES
wraps;//是否在 min 和 max 之间循环,默认 NO
动态实现:
#import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize myLabel; - (void)viewDidLoad { [super viewDidLoad]; myLabel = [[UILabel alloc]init]; myLabel.frame = self.view.bounds; myLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; myLabel.text = @"3"; myLabel.font = [UIFont boldSystemFontOfSize:48]; myLabel.textAlignment = NSTextAlignmentCenter; [self.view addSubview:myLabel]; UIStepper *myStepper = [[UIStepper alloc]init]; myStepper.value = 3; myStepper.minimumValue = 1; myStepper.maximumValue = 10; myStepper.stepValue = 2; myStepper.center = CGPointMake(200, 240); [myStepper addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:myStepper]; // Do any additional setup after loading the view, typically from a nib. } - (void) valueChange:(UIStepper *)myStepper{ myLabel.text = [NSString stringWithFormat:@"%2.0f",myStepper.value]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
#import <UIKit/UIKit.h> @interface ViewController : UIViewController @property (strong,nonatomic) UILabel *myLabel; @end