UIStepper

 

UIStepper

分类: IOS
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIStepper *stepper = [[UIStepper alloc] init];
    stepper.tag = 10;
    stepper.center = CGPointMake(160, 240);
    stepper.minimumValue = 1; //设置最小值
    stepper.maximumValue = 30; //设置最大值
    stepper.stepValue = 2; //每次递增2
    stepper.value = 15; //初始值
    [stepper setWraps:YES]; //是否循环
    [stepper addTarget:self action:@selector(doTest) forControlEvents:UIControlEventValueChanged];
    
    
    [self.view addSubview:stepper];
    [stepper release];

}

-(void)doTest
{
    UIStepper *per = (UIStepper*)[self.view viewWithTag:10];
    
    if (per.continuous)
    {
        NSLog(@"Y");
        int a = per.value;  //获取当前值
        NSLog(@"%d", a);
    }
    else 
    {
        NSLog(@"N");
    }
}
原文地址:https://www.cnblogs.com/iOS-mt/p/4143682.html