ios - 如何格式化 iOS 7 UIPickerView 以仅显示 3 个选项? IE。一上一下主动选择?
<p><p>我想将 iOS 7 UIPickerView 格式化为仅显示三个选项。 IE。一个在所选选项之上,一个在所选选项之下。我还想将文本格式化为小于默认值。我如何做到这一点?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>实现这些委托(delegate)方法将为您提供一个包含 3 行的选择器 View ,并让您自定义字体、颜色等... </p>
<pre><code> - (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 = [ initWithFrame:frame];
//FORMAT THE FONT FOR THE LABEL AS YOU LIKE
pickerRowLabel.backgroundColor = ;
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
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何格式化 iOS 7 UIPickerView 以仅显示 3 个选项? IE。一上一下主动选择?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/22603290/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/22603290/
</a>
</p>
页:
[1]