我想格式化iOS 7 UIPickerView以仅显示三个选择。即所选选项上方一个,下方下方一个。我还想将文本格式设置为小于默认值。我该如何实现?
最佳答案
实现这些委托方法将为您提供3行选择器视图,并允许您自定义字体,颜色等。
- (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个选择?即主动选择之上一之下?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22603290/