IOS的基本控件的使用-步进器&分栏控制器

  ViewController.h

//  步进器&分栏控件

//

//  Created by mac on 2016/10/28.

//  Copyright © 2016 mac. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface ViewController : UIViewController


{

    

    //  定义步进器对象

    //  按照一定的数字来调整某个数据

    UIStepper* _stepper;

    

    

    //  分栏控制器

    UISegmentedControl* _segControl;

    


}


@property (retain , nonatomic ) UIStepper* stepper;


@property (retain , nonatomic ) UISegmentedControl* segControl;



@end

  ViewController.m

//  步进器&分栏控件

//

//  Created by mac on 2016/10/28.

//  Copyright © 2016 mac. All rights reserved.

//


#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, typically from a nib.


    //  创建步进器对象

    _stepper = [[UIStepper alloc] init];

    

    //  设置位置,宽高不能改变

    _stepper.frame = CGRectMake(100, 100, 100, 100);

    

    //  设置步进器的最小值

    _stepper.minimumValue = 0;

    

    //  设置步进器的最大值

    _stepper.maximumValue = 10;

    

    //  设置步进器的当前值,默认值为0

    _stepper.value = 10;

    

    //  设置步进值,每次向前或者向后的步伐值

    _stepper.stepValue = 1;

    

    //  是否可以重复响应事件操作

    //  意思就是按住按钮的时候是否连续的响应

    _stepper.autorepeat = YES;

    

    //  是否将步进结果通过事件函数响应出来

    //  值为NO的时候按住按钮松开的时候只响应最后一步

    _stepper.continuous = YES;

    

    //  添加事件函数

    //  1:函数实现体

    //  2:函数体

    //  3:事件改变状态

    [_stepper addTarget:self action:@selector(stepChange) forControlEvents:UIControlEventValueChanged];

    

    [self.view addSubview:_stepper];

    

    

    //  创建分栏控件

    _segControl = [[UISegmentedControl alloc] init];

    

    //  设置位置大小宽度可以变,高度不可以变

    _segControl.frame = CGRectMake(10, 200, 300, 40);

    

    //  添加一个按钮元素

    [_segControl insertSegmentWithTitle:@"0" atIndex:0 animated:NO];

    

    //  p1:按钮选项文字

    //  p2:按钮的索引位置

    //  p3:是否有插入的动画效果

    [_segControl insertSegmentWithTitle:@"5" atIndex:1 animated:NO];

    [_segControl insertSegmentWithTitle:@"10" atIndex:2 animated:NO];

    [_segControl insertSegmentWithTitle:@"30" atIndex:2 animated:NO];

    [_segControl insertSegmentWithTitle:@"50" atIndex:2 animated:NO];

    

    //  当前默认按钮索引设置

    _segControl.selectedSegmentIndex = 0;

    

    [_segControl addTarget:self action:@selector(segChange) forControlEvents:UIControlEventValueChanged];

    

    [self.view addSubview:_segControl];

    

}

-(void) stepChange

{


    NSLog(@"step press value =%f",_stepper.value);

}


-(void) segChange

{

    NSLog(@"%ld",_segControl.selectedSegmentIndex);

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



@end



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值