我想将 iOS 7 UIPickerView 格式化为仅显示三个选项。 IE。一个在所选选项之上,一个在所选选项之下。我还想将文本格式化为小于默认值。我如何做到这一点?
Best Answer-推荐答案 strong>
实现这些委托(delegate)方法将为您提供一个包含 3 行的选择器 View ,并让您自定义字体、颜色等...
- (NSInteger)numberOfComponentsInPickerViewUIPickerView *)pickerView {
return 1;
}
- (UIView *)pickerViewUIPickerView *)pickerView viewForRowNSInteger)row forComponentNSInteger)component reusingViewUIView *)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)pickerViewUIPickerView *)pickerView numberOfRowsInComponentNSInteger)component {
return 3; //MOST LIKELY YOUR ARRAY OF OBJECTS COUNT
}
关于ios - 如何格式化 iOS 7 UIPickerView 以仅显示 3 个选项? IE。一上一下主动选择?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/22603290/
|