UIStepper详解

首先我们跳入UIStepper中,看到了他的属性以及方法,下面一一实验

@property(nonatomic,getter=isContinuous) BOOL continuous; // if YES, value change events are sent any time the value changes during interaction. default = YES
@property(nonatomic) BOOL autorepeat;                     // if YES, press & hold repeatedly alters value. default = YES
@property(nonatomic) BOOL wraps;                          // if YES, value wraps from min <-> max. default = NO

@property(nonatomic) double value;                        // default is 0. sends UIControlEventValueChanged. clamped to min/max
@property(nonatomic) double minimumValue;                 // default 0. must be less than maximumValue
@property(nonatomic) double maximumValue;                 // default 100. must be greater than minimumValue
@property(nonatomic) double stepValue;                    // default 1. must be greater than 0

// The tintColor is inherited through the superview hierarchy. See UIView for more information.
@property(null_resettable,nonatomic,strong) UIColor *tintColor NS_AVAILABLE_IOS(6_0);

// a background image which will be 3-way stretched over the whole of the control. Each half of the stepper will paint the image appropriate for its state
- (void)setBackgroundImage:(nullable UIImage*)image forState:(UIControlState)state NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
- (nullable UIImage*)backgroundImageForState:(UIControlState)state NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;

// an image which will be painted in between the two stepper segments. The image is selected depending both segments' state
- (void)setDividerImage:(nullable UIImage*)image forLeftSegmentState:(UIControlState)leftState rightSegmentState:(UIControlState)rightState NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
- (nullable UIImage*)dividerImageForLeftSegmentState:(UIControlState)state rightSegmentState:(UIControlState)state NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;

// the glyph image for the plus/increase button
- (void)setIncrementImage:(nullable UIImage *)image forState:(UIControlState)state NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
- (nullable UIImage *)incrementImageForState:(UIControlState)state NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;

// the glyph image for the minus/decrease button
- (void)setDecrementImage:(nullable UIImage *)image forState:(UIControlState)state NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
- (nullable UIImage *)decrementImageForState:(UIControlState)state NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;

//解答

UIStepper * step = [[UIStepper alloc] initWithFrame:CGRectMake(120, 230, 100, 100)];

    /*
     continuous 控制是否持续触发UIControlEventValueChanged事件。默认YES,即当按住时每次值改变都触发一次UIControlEventValueChanged事件,否则只有在释放按钮时触发UIControlEventValueChanged事件。
     autorepeat 控制是否在按住是自动持续递增或递减。默认YES。
     wraps 控制值是否在[minimumValue,maximumValue]区间内循环。默认NO。
     */
    step.continuous = YES;
    step.autorepeat = YES;
    step.wraps = NO;


    /*
     value 当前所表示的值,默认0.0
     minimumValue 最小可以表示的值,默认0.0
     maximumValue 最大可以表示的值,默认100.0
     stepValue 每次递增或递减的值,默认1.0
     */
    step.value = 10;
    step.minimumValue = 2;
    step.maximumValue = 99;
    step.stepValue = 1;
//    step.tintColor = [UIColor redColor];

    //方法
//    [step setBackgroundImage:[UIImage imageNamed:@"a"] forState:UIControlStateNormal];
//    UIImage * image = [step backgroundImageForState:UIControlStateNormal];
//    [step setDividerImage:[UIImage imageNamed:@"a"] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal];//中间图片
    NSLog(@"%@",[step dividerImageForLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal]);
//    [step setIncrementImage:[UIImage imageNamed:@"a"] forState:UIControlStateNormal];//加号
    NSLog(@"%@",[step incrementImageForState:UIControlStateNormal]);
//    [step setDecrementImage:[UIImage imageNamed:@"a"] forState:UIControlStateNormal];//减号图片
    NSLog(@"%@",[step decrementImageForState:UIControlStateNormal]);
    [step addTarget:self action:@selector(step:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:step];

跳转方法

-(void)step:(UIStepper*)step{

    step.alpha = step.value;
    NSLog(@"%f",step.value);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值