iOS 橫向滾動選擇器:MLPickerScrollView

jopen 9年前發布 | 11K 次閱讀 iOS開發 移動開發 MLPickerScrollView

Introduction:

  • The easiest way to use PickerScrollView
  • 這是一個對橫向滾動選擇器的自定義UI控件,只要幾行代碼就可以集成類似橫向滾動中間放大的效果并且選中的功能。
  • </ul>

    Presentation:

    模擬場景<選擇折扣>

    • 效果:有滾動選中中間Item和點擊效果Item
    • </ul>

      Usage:

      代碼例子:選擇場景為 選擇折扣

         // 1.數據源
          data = [NSMutableArray array];
          NSArray *titleArray = @[@"不打折",@"9折",@"8折",@"7折",@"6折",@"5折",@"4折",@"3折",@"2折",@"1折"];
          for (int i = 0; i < titleArray.count; i++) {
              MLDemoModel *model = [[MLDemoModel alloc] init];
              model.dicountTitle = [titleArray objectAtIndex:i];
              [data addObject:model];
          }
      
          // 2.初始化
          _pickerScollView = [[MLPickerScrollView alloc] initWithFrame:CGRectMake(kItemW, SCREEN_HEIGHT - 350, SCREEN_WIDTH - kItemH, kItemH)];
          _pickerScollView.backgroundColor = [UIColor whiteColor];
          _pickerScollView.itemWidth = _pickerScollView.frame.size.width / 5;
          _pickerScollView.itemHeight = kItemH;
          _pickerScollView.firstItemX = (_pickerScollView.frame.size.width - _pickerScollView.itemWidth) * 0.5;
          _pickerScollView.dataSource = self;
          _pickerScollView.delegate = self;
          [self.view addSubview:_pickerScollView];
      
          // 3.刷新數據
          [_pickerScollView reloadData];
      
          // 4.滾動到對應折扣
          self.discount = (NSInteger)arc4random()%10;
          if (self.discount) {
              NSInteger number;
              for (int i = 0; i < data.count; i++) {
                  MLDemoModel *model = [data objectAtIndex:i];
                  if (model.dicountIndex == self.discount) {
                      number = i;
                  }
              }
               _pickerScollView.seletedIndex = number;
              [_pickerScollView scollToSelectdIndex:number];
          }

      項目主頁:http://www.baiduhome.net/lib/view/home/1439648836426

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!