iOS選取器視圖控制項(UIPickerView)使用方法總結

來源:互聯網
上載者:User

標籤:

iOS中UIPickerView使用總結

UIPickerView是iOS中的原生選取器控制項,使用方便,用法簡單,效果漂亮。

@property(nonatomic,assign) id<UIPickerViewDataSource> dataSource;                

@property(nonatomic,assign) id<UIPickerViewDelegate>   delegate; 

設定資料來源和代理

@property(nonatomic) BOOL showsSelectionIndicator;

是否顯示選擇框,在iOS7之後這個屬性沒有任何效果

@property(nonatomic,readonly) NSInteger numberOfComponents;

擷取分區數

- (NSInteger)numberOfRowsInComponent:(NSInteger)component;

擷取某一分區的行數

- (CGSize)rowSizeForComponent:(NSInteger)component;

擷取某一分區行的尺寸

- (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component;

擷取某一分區某一行的視圖

- (void)reloadAllComponents;

重載所有分區

- (void)reloadComponent:(NSInteger)component;

重載某一分區

- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated; 

設定選中某一分區某一行

- (NSInteger)selectedRowInComponent:(NSInteger)component;  

返回某一分區選中的行


資料來源代理中的方法:

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

設定分區數

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

根據分區設定行數


代理中的方法:

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

設定分區寬度

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

設定分區行高

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

設定某一行顯示的標題

- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component;

通過屬性字串設定某一行顯示的標題


- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;

設定某一行顯示的view視圖


- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;

選中某一行時執行的回調


iOS選取器視圖控制項(UIPickerView)使用方法總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.