zoukankan      html  css  js  c++  java
  • UIPickerview 基本使用

    // 选择框
        UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 100, 320, 216)];
        // 显示选中框
        pickerView.showsSelectionIndicator=YES;
        pickerView.dataSource = self;
        pickerView.delegate = self;
        [self.view addSubview:pickerView];
        [pickerView release];
            _proTimeList = [[NSArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",nil];
        _proTitleList = [[NSArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",nil
     
     
    // pickerView 列数
    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
        return 2;
    }
     
    // pickerView 每列个数
    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
        if (component == 0) {
            return [_proTitleList count];
        }
         
        return [_proTimeList count];
    }
     
    // 每列宽度
    - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
         
        if (component == 1) {
            return 40;
        }
        return 180;
    }
    // 返回选中的行
    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    {
        if (component == 0) {
            _proNameStr = [_proTitleList objectAtIndex:row];
        } else {
            _proTimeStr = [_proTimeList objectAtIndex:row];
        }
     
    }
     
    //返回当前行的内容,此处是将数组中数值添加到滚动的那个显示栏上
    -(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
    {
        if (component == 0) {
            return [_proTitleList objectAtIndex:row];
        } else {
            return [_proTimeList objectAtIndex:row];
     
        }
    }
  • 相关阅读:
    iOS开发常用的第三方框架
    回传值(代理、通知、block)
    给控制器添加工具栏(Swift语言)
    Swift语言 代码添加文本输入框 和 占位文本
    MD5加密运算
    Xcode7.0设置网络白名单
    base64加密解密文件
    关于iOS应用管理之九宫格的坐标计算以及与UIScrollView的结合
    3、Struts2中的参数传值
    2、Action的多种写法配置
  • 原文地址:https://www.cnblogs.com/anjiubo/p/5263584.html
Copyright © 2011-2022 走看看