此範例為點擊stepper,計數顯示在label上

1.storyboard中加入stepper, label

2.設定stepper的行為autorepeat, continus

3.建立程式關聯性

4.當stepper改變時, 設定label文字顯示 

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UILabel *valueLabel;
- (IBAction)changeStepper:(UIStepper *)sender;

@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.
}

- (IBAction)changeSteper:(UIStepper *)sender {
    
    _valueLabel.text = [NSString stringWithFormat:@"%.0f",sender.value];
    
}
@end

arrow
arrow

    Will 發表在 痞客邦 留言(0) 人氣()