iOS 中UIPickerView使用總結(jié)

UIPickerView是iOS中的原生選擇器控件,使用方便,用法簡(jiǎn)單,效果漂亮。

注意:showsSelectionIndicator選擇欄屬性在iOS7之后貌似沒有任何效果

@property(nonatomic,assign) id<UIPickerViewDataSource> dataSource;                
@property(nonatomic,assign) id<UIPickerViewDelegate>   delegate; 
// 設(shè)置數(shù)據(jù)源和代理

@property(nonatomic) BOOL showsSelectionIndicator;
// 是否顯示選擇框,在iOS7之后這個(gè)屬性沒有任何效果

@property(nonatomic,readonly) NSInteger numberOfComponents;
// 獲取分區(qū)數(shù)

- (NSInteger)numberOfRowsInComponent:(NSInteger)component;
// 獲取某一分區(qū)的行數(shù)

- (CGSize)rowSizeForComponent:(NSInteger)component;
// 獲取某一分區(qū)行的尺寸

- (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component;
// 獲取某一分區(qū)某一行的視圖

- (void)reloadAllComponents;
// 重載所有分區(qū)

- (void)reloadComponent:(NSInteger)component;
// 重載某一分區(qū)

- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated; 
// 設(shè)置選中某一分區(qū)某一行

- (NSInteger)selectedRowInComponent:(NSInteger)component;  
// 返回某一分區(qū)選中的行

// 數(shù)據(jù)源代理中的方法:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
// 設(shè)置分區(qū)數(shù)

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
// 根據(jù)分區(qū)設(shè)置行數(shù)

// 代理中的方法:
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component;
// 設(shè)置分區(qū)寬度

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component;
// 設(shè)置分區(qū)行高

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
// 設(shè)置某一行顯示的標(biāo)題

- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component;
// 通過屬性字符串設(shè)置某一行顯示的標(biāo)題

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;
// 設(shè)置某一行顯示的view視圖

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
// 選中某一行時(shí)執(zhí)行的回調(diào)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • WebSocket-Swift Starscream的使用 WebSocket 是 HTML5 一種新的協(xié)議。它實(shí)...
    香橙柚子閱讀 24,735評(píng)論 8 183
  • 這是一個(gè)特殊的年代,也是一個(gè)特殊的時(shí)期,百家爭(zhēng)鳴,各行各業(yè),百業(yè)待變。從實(shí)體到互聯(lián)網(wǎng),從互聯(lián)網(wǎng)再到實(shí)體,虛...
    陳毓灃閱讀 235評(píng)論 0 0
  • 籌備組成員名單公示到今天第四天
    華園曾輝閱讀 456評(píng)論 0 0
  • 讀經(jīng)時(shí)間: 2017年4月14日 星期五 多云 讀經(jīng)人員: 媽媽 讀經(jīng)內(nèi)容: 《易經(jīng)》系辭上傳 第一章-第四章...
    161d968e601f閱讀 164評(píng)論 0 0
  • 很多人在看到電影電視里煽情的地方時(shí)容易落淚,但不知道有沒有人和我一樣,在一些“奇怪”的地方容易鼻酸落淚。 記得...
    小貝子Vivian閱讀 2,079評(píng)論 0 1

友情鏈接更多精彩內(nèi)容