IOS開發UI基礎UIPikerView的屬性

來源:互聯網
上載者:User

標籤:

UIPikerView的屬性


 1. numberOfComponents:返回UIPickerView當前的列數
NSInteger num = _pickerView.numberOfComponents;
NSLog( @"%d", num);


2. - (NSInteger)numberOfRowsInComponent:(NSInteger)component; 返回component列中有多少行。
NSInteger numInCp = [_pickerView numberOfRowsInComponent:0];
NSLog(@"%d",numInCp);


3. -  (CGSize)rowSizeForComponent:(NSInteger)component; 返回component中一行的尺寸。

CGSize size = [_pickerView rowSizeForComponent:0];
NSLog(@"%@", NSStringFromCGSize(size));


    •    delegate:
2.0 設定UIPickerView代理
_pickerView.delegate = self;
// 設定UIPickView每行顯示的內容
2.1 - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return @"showData";
}


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

// 返回一個視圖,用來設定pickerView的每行顯示的內容。
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    UIView *myView=[[UIView alloc]init];
    myView.backgroundColor = [UIColor redColor];
    return myView;
}


    •    dataSource:資料來源
#pragma mark  - dataSource method
// 設定每列顯示3行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return 3;
}
// 設定顯示2列
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}


4. showsSelectionIndicator:是否顯示指標,預設為NO 
_pickerView.showsSelectionIndicator = NO;

注意:設定UIPickerView的行數與列數需要設定資料來源,遵守UIPickerViewDataSource,設定UIPickerView的內容需要設定代理,並且遵守代理方法UIPickerViewDelegate。


5.-(void)pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
當點擊UIPickerView的某一列中某一行的時候,就會調用這個方法。


6. 返回第component列每一行的高度
- (CGFloat)pickerView:(UIPickerView *)pickerView
rowHeightForComponent:(NSInteger)component;

7.重新整理某一列的資料
一旦調用了這個方法,就會重新給資料來源發送訊息計算這列的行數、重新給代理髮送訊息獲得這列的內容
[pickerView reloadComponent:1];


8. 重新整理所有列的資料
- (void)reloadAllComponents;


9. 返回選中的是第component列的第幾行。
- (NSInteger)selectedRowInComponent:(NSInteger)component;                                   



IOS開發UI基礎UIPikerView的屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.