当前位置: 首页 > 工具软件 > iOS7 Sampler > 使用案例 >

IOS7 UIPickerView

苗烈
2023-12-01

  在头文件中饮用UIPickerView的两个代理 <UIPickerViewDelegate ,UIpickerViewDataSource>

    UIPickerView *pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(100, 250, 200, 100)];

    pickerView.delegate = self ;
    pickerView.dataSource = self ;
    [pickerView reloadAllComponents];

    [self.view addSubview:pickerView];



-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    NSLog(@"row = %d  component = %d" ,row ,component);

}

-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    if (!view)
    {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 60, 30)];
        label.text = [NSString stringWithFormat:@"row%d",row];
        label.textColor = [UIColor blueColor];
        view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 70, 30)];
        view.backgroundColor = [UIColor greenColor];
        [view addSubview:label];
    }
    
    return view ;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return  3;
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 3;
}

-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 20.0f;
}





 类似资料:

相关阅读

相关文章

相关问答