我想格式化 iOS 7 UIPickerView 以仅显示三个选项。 IE。所选选项上方一个,下方一个。我还想将文本格式设置为小于默认值。我如何实现这一目标?
最佳答案
实现这些委托(delegate)方法将为您提供一个 3 行的选择器 View ,并让您自定义字体、颜色等...
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel *pickerRowLabel = (UILabel *)view;
if (pickerRowLabel == nil) {
CGRect frame = //YOUR PICKERVIEW FRAME. HEIGHT IS 44 by default.
pickerRowLabel = [[UILabel alloc] initWithFrame:frame];
//FORMAT THE FONT FOR THE LABEL AS YOU LIKE
pickerRowLabel.backgroundColor = [UIColor clearColor];
pickerRowLabel.userInteractionEnabled = YES;
}
pickerRowLabel.text = //YOUR TEXT, MOST LIKELY FROM AN ARRAY ... ?
return pickerRowLabel;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return 3; //MOST LIKELY YOUR ARRAY OF OBJECTS COUNT
}
关于ios - 如何格式化 iOS 7 UIPickerView 以仅显示 3 个选择? IE。主动选择上面一个和下面一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22603290/