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];

        }

    }

  • 相关阅读:
    “TensorFlow 开发者出道计划”全攻略,玩转社区看这里!
    魔改合成大西瓜
    自定义注解!绝对是程序员装逼的利器!!
    Python中的join()函数的用法
    Python中的split()函数的用法
    linux 完全卸载mysql数据库
    域名被盗后还能不能找回
    在选择域名后缀时应该考虑到的问题
    什么叫域名劫持 和域名解析有什么区别
    河北重大技术需求系统04
  • 原文地址:https://www.cnblogs.com/lrr0618/p/5174494.html
Copyright © 2011-2022 走看看