zoukankan      html  css  js  c++  java
  • UI基础--UIStepper步进器

    直接上代码喽:

    .h

    @interface ViewController : UIViewController
    
    {
        //声明步进器对象
        UIStepper *_stepper;
    }
    
    //声明属性
    @property (nonatomic, strong) UIStepper *stepper;
    
    @end

    .m

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @property (nonatomic, strong) UILabel *label;
    
    @end
    
    @implementation ViewController
    
    //同步属性和成员变量
    @synthesize stepper = _stepper;
    
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
       
        self.view.backgroundColor = [UIColor whiteColor];
        
        //创建步进器对象
        UIStepper *sterper = [[UIStepper alloc]init];
        //设置Frame(大小为系统内设定);
        sterper.frame = CGRectMake(100, 100, 0, 0);
        //设置每次增加的数量
        sterper.stepValue = 1;
        //设置最小值(默认为0)
        sterper.minimumValue = 0;
        //设置最大值(默认为100)
        sterper.maximumValue = 10;
        //从小到大(默认为NO)
        sterper.wraps = YES;
        //设置是否重复(默认为YES)
        sterper.autorepeat = YES;
        //是否连续(默认为YES)
        sterper.continuous = YES;
        //添加到当前视图上
        [self.view addSubview:sterper];
        
        self.stepper = sterper;
        
        /**
         创建Label,将值显示在Label上;
         */
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(50, 40, 100, 30)];
        label.backgroundColor = [UIColor lightGrayColor];
        label.textColor = [UIColor purpleColor];
        label.textAlignment = 1;
        [self.view addSubview:label];
        
        self.label = label;
        
        //添加步进器点击事件
        [sterper addTarget:self action:@selector(addCount:) forControlEvents:UIControlEventValueChanged];
        
    }
    //实现步进器事件
    - (void)addCount:(UIStepper *)steper{
        
        self.label.text = [NSString stringWithFormat:@"%.0f", steper.value];
        
    }
    
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
  • 相关阅读:
    Domain Logic approaches
    Load data local infile 实验报告
    eclipse导入Maven项目
    MYSQL数据库导入数据时出现乱码的解决办法
    mysql创建用户并分配权限
    CDI Features
    Java Design Patterr
    关联tomcat源代码
    Spring AOP Capabilities and Goals
    CDI FEATURES
  • 原文地址:https://www.cnblogs.com/LzwBlog/p/5685442.html
Copyright © 2011-2022 走看看