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
  • 相关阅读:
    Oracle目录结构及创建新数据库
    Oracle登陆及修改用户密码
    前端开发笔记
    2014年11月6日17:57:13
    游戏体验篇 二
    游戏前端开发随笔【2】
    游戏体验篇 一
    游戏 之 前端系统开发
    换个手机号也是醉了
    winsock2.h的SB东西
  • 原文地址:https://www.cnblogs.com/LzwBlog/p/5685442.html
Copyright © 2011-2022 走看看