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
  • 相关阅读:
    winfrom让窗体在屏幕右下角慢慢向上弹出
    winfrom的StatusStrip控件如何设置控件右对齐
    Winfrom通过Panel拖动无边框窗体
    优秀学习资源汇总
    hexo+github搭建博客跳坑
    博客园主题样式修改
    wxss无法调用本地资源图片
    微信小程序wx:for循环
    Git常用命令总结
    git push解决办法: ! [remote rejected] master -> master (pre-receive hook declined)
  • 原文地址:https://www.cnblogs.com/LzwBlog/p/5685442.html
Copyright © 2011-2022 走看看