【问题标题】:How to customize picker view如何自定义选择器视图
【发布时间】:2016-10-19 04:44:40
【问题描述】:

我想在我的项目中自定义选择器视图。在 pickerview 单元格中添加不同类型的图像并且还想减少 pickerview 高度。

我给你看图片以便更多理解。

如何实现这种类型的pickerview?我检查了自定义演示,但没有找到任何信息。

【问题讨论】:

    标签: ios objective-c uipickerview


    【解决方案1】:

    将条件应用于 UIPickerView 的委托方法。

      - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"your image number %@.png", (long)row]];
    UIImageView *imageview= [[UIImageView alloc] initWithImage:img];
    imageview.frame = CGRectMake(-70, 10, 60, 40);
    
    UILabel *channelLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, -5, 80, 60)];
    channelLabel.text = [NSString stringWithFormat:@"%@", [myArray objectAtIndex:row]];
    channelLabel.textAlignment = UITextAlignmentLeft;
    channelLabel.backgroundColor = [UIColor clearColor];
    
    UIView *tmpView_row = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 110, 60)];
    [tmpView_row insertSubview:imageview atIndex:0];
    [tmpView_row insertSubview:channelLabel atIndex:1];
    
    return tmpView_row;
    }
    

    【讨论】:

      猜你喜欢
      • 2013-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-23
      • 1970-01-01
      • 1970-01-01
      • 2012-10-15
      相关资源
      最近更新 更多