zoukankan      html  css  js  c++  java
  • UISB 进步器 分栏控制器

    ViewController.h

    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController
    {
        
        //定义步进器对象
        //按照一定的数值来调整某个数值
        UIStepper* _stepper;
        
        //分栏控制器
        UISegmentedControl* _segControl;
        
        
        
        
    }
    
    //控制器属性 对于外部使用
    @property(retain,nonatomic)UIStepper* stepper;
    
    @property(retain,nonatomic)UISegmentedControl* segControl;
    
    @end

    ViewController.m

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    @synthesize stepper=_stepper;
    @synthesize segControl=_segControl;
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        
        //创建步进器物对象
        _stepper =[[UIStepper alloc]init];
        //设置位置 宽高不能变更
        _stepper.frame=CGRectMake(100, 100, 80, 40);
        
        _stepper.minimumValue=0;
        
        _stepper.maximumValue=100;
        _stepper.value=10;
        //设置步进值 每次向前或向后步进的步伐值
        _stepper.stepValue=1;
        //是否可以重复响应事件操作 按住 自动添加
        _stepper.autorepeat=YES;
        
        //是否将进步结果通过事件函数响应出来
        _stepper.continuous=YES;
        //添加事件函数
        //P1 函数实现体
        //P2 函数体
        //P3 事件值改变状态
        [_stepper addTarget:self action:@selector(stepChange) forControlEvents:UIControlEventValueChanged];
        
        [self.view addSubview:_stepper];
        
        
        //创建分栏控件
        _segControl=[[UISegmentedControl alloc]init];
        _segControl.frame = CGRectMake(10, 200, 300, 40);
        
        //参数 P1 按钮选项文字
        //P2 按钮索引位置
        //P3 是否有动画效果
        
        
        [_segControl insertSegmentWithTitle:@"0元" atIndex:0 animated:NO];
        
        [_segControl insertSegmentWithTitle:@"5元" atIndex:1 animated:NO];
        
        //当前默认按钮的索引
        _segControl.selectedSegmentIndex=0;
        [_segControl addTarget:self action:@selector(segChange) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:_segControl];
        
        
        
        
        
        
        
    }
    
    -(void)stepChange
    {
        NSLog(@"step Change %f",_stepper.value);
        
    }
    
    -(void)segChange
    {
        NSLog(@"%d",_segControl.selectedSegmentIndex);
        
    }
    
    @end
  • 相关阅读:
    python3字典删除元素和添加元素的几种方法
    查看ef core 3.1/3.0/2.1.2生成的sql语句
    C#Qrcode生成二维码支持带标题
    .net RabbitMQ 介绍、安装、运行
    Golang之初探
    MySql5.7多实例配置教程
    Centos7 安装MySql 5.7
    sqlserver智能提示插件-sql prompt(9.4.6)的安装及注册流程
    ABP框架(asp.net core 2.X+Vue)模板项目学习之路(二)--切换MySql数据库
    ABP框架(asp.net core 2.X+Vue)模板项目学习之路(一)
  • 原文地址:https://www.cnblogs.com/zhangqing979797/p/13664231.html
Copyright © 2011-2022 走看看