ios - 如何格式化 iOS 7 UIPickerView 以仅显示 3 个选择? IE。主动选择上面一个和下面一个?

标签 ios objective-c uipickerview

我想格式化 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/

相关文章:

ios - UITableViewCell - 如何在计算 heightForRowAtIndex 之前向 UITextView 添加约束

iOS Game Center 将排行榜和成就移至 2 个游戏组

ios - 更新 UICollectionView 中的 UILabel

ios - AutoLayout Storyboard 约束 - 如何在代码中修改以在 Orientation 更改中使用此修改

ios - UITableView:scrollToRowAtIndexPath或setContentOffset动画速度

iphone - 如何在运行时注册/注销协议(protocol)?

iphone - 在 Xcode 中将图像添加到 UITextField 中?

ios - 无法让 UIPicker 文本着色粘贴

ios - 如何创建 "Drop-Up-Menu"?

ios - dequeueReusableCellWithIdentifier 从不返回 nil