欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS中的UIStepper數(shù)值加減器用法指南

 更新時間:2016年05月27日 09:24:15   投稿:goldensun  
UIStepper可以有許多應用場景,比如在購物應用中制作按鈕對購買商品的數(shù)量進行增或減,下面我們就一起來看看iOS中的UIStepper數(shù)值加減器用法指南

UIStepper可以連續(xù)增加或減少一個數(shù)值。控件的外觀是兩個水平并排的按鈕構成,一個顯示為“+”,一個顯示為“-”。
該控件的一個有趣的特征是當用戶按住“+”,“-”按鈕時,根據(jù)按住的時間長度,空間值的數(shù)字也以不同的數(shù)字改變。按住的時間越長,數(shù)值改變的越快??梢詾閁IStepper設定一個數(shù)值范圍,比如0-99. 它的顯示效果如下:

1. 屬性說明
value: 當前所表示的值,默認為0.0;
minimumValue: 最小可以表示的值,默認0.0;
maximumValue: 最大可以表示的值,默認100.0;
stepValue: 每次遞增或遞減的值,默認為1.0;

2.如何判斷加("+")減("-")
(1)通過設置一個   double* previousValue;   *// *用來記錄Stepper.value*的上一次值
(2)在對想操作的對象進行操作后,將Stepper.value = 0   

復制代碼 代碼如下:

#pragma mark - 設置UIStepper
- (void)createUIStepper{

    UIStepper * stepperButton = [[UIStepper alloc]initWithFrame:CGRectMake(225, 500, 30, 10)];
    [stepperButton addTarget:self action:@selector(controlStepperValue:) forControlEvents:UIControlEventValueChanged];
    stepperButton.maximumValue = 100.0;
    stepperButton.minimumValue = 0.0;
    stepperButton.value = INITUISTEPPERVALUE;
    stepperButton.stepValue = 1.0;
    stepperButton.continuous = YES;
    stepperButton.wraps = NO;
    stepperButton.autorepeat = YES;
    [self.view addSubview:stepperButton];
    [stepperButton release];

}


復制代碼 代碼如下:

- (void)controlStepperValue:(UIStepper *)stepper{

    if (_segment.selectedSegmentIndex == 0) {
        if (stepper.value > previousValue) {
            CGRect redRect = _redView.frame;
            redRect.size.height += 5;
            _redView.frame = redRect;
        } else {

            CGRect redRect = _redView.frame;
            redRect.size.height -= 5;
            _redView.frame = redRect;
        }
        previousValue = stepper.value;
    }else{
        if (stepper.value > previousValue) {
            CGRect redRect = _greenView.frame;
            redRect.size.height += 5;
            _greenView.frame = redRect;
        } else {

            CGRect redRect = _greenView.frame;
            redRect.size.height -= 5;
            _greenView.frame = redRect;
        }
        previousValue = stepper.value;
    }

}

3.基本用法整理
初始化控件

復制代碼 代碼如下:

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

設置控制器值是否連續(xù)觸發(fā)變化
復制代碼 代碼如下:

@property(nonatomic,getter=isContinuous) BOOL continuous;

若設置為YES,則長按會連續(xù)觸發(fā)變化,若設置為NO,只有在按擊結束后,才會觸發(fā)。
設置長按是否一直觸發(fā)變化
復制代碼 代碼如下:

@property(nonatomic) BOOL autorepeat;

若設置為YES,則長按值會一直改變,若設置為NO,則一次點擊只會改變一次值
設置控制器的值是否循環(huán)(到達邊界后,重頭開始,默認為NO)
復制代碼 代碼如下:

@property(nonatomic) BOOL wraps;

設置控制器的值
復制代碼 代碼如下:

@property(nonatomic) double value;

設置控制器的最大值和最小值
復制代碼 代碼如下:

@property(nonatomic) double minimumValue;//默認為0
@property(nonatomic) double maximumValue; //默認為100

設置控制器的步長
復制代碼 代碼如下:

@property(nonatomic) double stepValue;

設置控制器風格顏色
復制代碼 代碼如下:

@property(nonatomic,retain) UIColor *tintColor;

設置控制器背景圖片
復制代碼 代碼如下:

- (void)setBackgroundImage:(UIImage*)image forState:(UIControlState)state;

獲取背景圖片
復制代碼 代碼如下:

- (UIImage*)backgroundImageForState:(UIControlState)state;

通過左右按鈕的狀態(tài)設置分割線的圖片
復制代碼 代碼如下:

- (void)setDividerImage:(UIImage*)image forLeftSegmentState:(UIControlState)leftState rightSegmentState:(UIControlState)rightState;

獲取分割線圖片
復制代碼 代碼如下:

- (UIImage*)dividerImageForLeftSegmentState:(UIControlState)state rightSegmentState:(UIControlState)state;

設置和獲取加號按鈕的圖片
復制代碼 代碼如下:

- (void)setIncrementImage:(UIImage *)image forState:(UIControlState)state;
- (UIImage *)incrementImageForState:(UIControlState)state;

設置和獲取減號按鈕的圖片
復制代碼 代碼如下:

- (void)setDecrementImage:(UIImage *)image forState:(UIControlState)state;
- (UIImage *)decrementImageForState:(UIControlState)state;

相關文章

最新評論