美文网首页
UIPickerView

UIPickerView

作者: DDY | 来源:发表于2016-11-07 16:17 被阅读74次

    创建

    设置000~179,height取162
    设置180~215,height取180
    设置216~+ ∞,height取216

    UIPickerView *pickerV = [[UIPickerView alloc] initWithFrame:CGRectMake(0, SWScreenH-216, 100, 216)];
    pickerV.dataSource = self;
    pickerV.delegate = self;
    [self.view addSubview:pickerV];
    

    属性

    • userInteractionEnabled 继承而来,是否允许交互(默认YES)
    • showsSelectionIndicator 设置不设置无变化
    • dataSource 必需
    • delegate 交互必需
    • numberOfComponents 获取分组数(只读)
    • textColor 可通过KVC调用[pickerV setValue:redColor forKey:@"textColor"];

    方法

    // 获取指定分组component中的行数
    - (NSInteger)numberOfRowsInComponent:(NSInteger)component;
    // 获取单元格的Size
    - rowSizeForComponent: ;
    // 获取pickerView:viewForRow:forComponent:reusingView:中定义的View,未实现或行/组不可用时返回nil
    - viewForRow: forComponent: ;
    // 刷新所有分组
    - reloadAllComponents;
    // 刷新指定分组
    - reloadComponent: ;
    // 选中指定分组中的一行
    - selectRow: inComponent: animated: ;  
    // 获得指定分组中选中的行
    - selectedRowInComponent: ;  
    

    数据源UIPickerViewDataSource

    //设置分组数
    - numberOfComponentsInPickerView: ;
    //设置各分组的行数
    - pickerView: numberOfRowsInComponent: ;
    

    委托UIPickerViewDelegate

    //设置分组的宽
    - pickerView: widthForComponent: ;
    // 设置单元格的高
    - pickerView: rowHeightForComponent: ;
    
    单元格中内容的展示,以下三种方法三选一
    //设置显示普通字符串
    - pickerView: titleForRow:  forComponent: ;
    // 设置显示属性字符串,该方法和普通字符串方法都实现了,效果是属性字符串
    - pickerView: attributedTitleForRow: forComponent: ;
    //自定义显示视图
    - pickerView: viewForRow: forComponent: reusingView: ;
    
    // 选中时委托方法,单元格动画停止即调用,不一定手点击
    -pickerView: didSelectRow: inComponent: ;
    

    附加

    http://www.cnblogs.com/Rong-Shengcom/p/6485570.html

    相关文章

      网友评论

          本文标题:UIPickerView

          本文链接:https://www.haomeiwen.com/subject/tqyouttx.html