zoukankan      html  css  js  c++  java
  • UIPickerView 循环滚动(一种假象)

    因为网上没有查到相关方法,故而采用一种假象的方法来实现,选项循环滚动

    - (void)viewDidLoad {

        [super viewDidLoad];

        /**

         UIPickerView 选择器

         */

        CGFloat Y = [UIScreen mainScreen].bounds.size.height-120;

        CGFloat W = [UIScreen mainScreen].bounds.size.width;

        CGFloat H = 120;

        UIPickerView *pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, Y, W, H)];

        pickerView.showsSelectionIndicator = YES;

        pickerView.backgroundColor = [UIColor whiteColor];

        pickerView.dataSource = self;

        pickerView.delegate = self;

        [self.view addSubview:pickerView];

        

        //数据源

        self.group = @[@[@"1",@"2",@"3"],@[@"11",@"22",@"33",@"44"],@[@"111",@"222",@"333"]];

        

        //设定 默认选中的 一行(比如:1 2 3...6 7 8...10,默认选择在“5”上)

    //    [pickerView selectRow:5 inComponent:1 animated:YES];

        for (int i = 0; i<self.group.count; i++) {

            [pickerView selectRow:150 inComponent:i animated:YES];

        }

    }

    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {

        return self.group.count;

    }

    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {

        NSArray *arr = self.group[component];

        return arr.count * 100;

    }

    -(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{

        return 50;

    }

    -(CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{

        return 50;

    }

    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {

        if (component == 1) {

            return [self.group[component] objectAtIndex:row % 4];

        }else{

            return [self.group[component] objectAtIndex:row % 3];

        }

    }

  • 相关阅读:
    vue-修改vue项目运行端口号
    任正非521央视采访全文
    是施压还是真的决裂?
    贸易战风波继续
    华为对封杀的态度和格局
    美国封锁对华为的影响
    布鲁克斯法则 (Brooks's Law)
    2019第20周日
    如何让自己走的更远
    如何应对中年危机
  • 原文地址:https://www.cnblogs.com/lrr0618/p/5174494.html
Copyright © 2011-2022 走看看