【问题标题】:change UIPicker highlighted tab width更改 UIPicker 突出显示的选项卡宽度
【发布时间】:2013-10-22 08:16:01
【问题描述】:

我在我的一个项目中使用 UIPicker。

我的 UIPickerView 的大小和位置为

 58, 264, 204, 216
  x   y  width height

我正在做 iOS 7 兼容的应用程序。

在 iOS 7 中,我只想显示宽度为 204,但在 iOS 6 及更早版本中,我想显示宽度为 300。

为此,以下是我所做的。

-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{

    if (IS_DEVICE_RUNNING_IOS_7_AND_ABOVE()) {
    NSLog(@"changing font...");
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 204, 44)]; // your frame, so picker gets "colored"

        label.textColor = [UIColor blackColor];
        label.font = [UIFont fontWithName:localize(@"myFontName") size:14];
        label.textAlignment = NSTextAlignmentCenter;

        label.text = [arrayGender objectAtIndex:row];

        return label;
    } else {
        [pickerView setFrame: CGRectMake(10, 264, 300, 216)];
        pickerView.backgroundColor = [UIColor clearColor];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 260, 44)];

        label.textColor = [UIColor blackColor];
        label.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:14];

        label.text = [NSString stringWithFormat:@"%@", [arrayGender objectAtIndex:row]];
        return label;
    }
}

这是完美的工作。

问题出在荧光笔上。荧光笔大小固定为 204(这是在 IB 中为 UIPicker 设置的 size-width)

知道如何处理这个荧光笔吗?

通过荧光笔,以下是我的意思示例。

下面是我所说的实际图像。

【问题讨论】:

    标签: ios objective-c ios7 uipicker


    【解决方案1】:

    看起来您应该将自己的 UIView 作为自定义选择指示器。详情请看here

    【讨论】:

      【解决方案2】:

      我通过反转东西解决了它。

      在 IB 中,我创建了宽度为 320 的 UIPicker 视图,并在代码中调整了宽度。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-26
        相关资源
        最近更新 更多