iOS 7 UIPickerView非选定行曲率修改多个组件 [英] iOS 7 UIPickerView non-selected row curvature modification multiple components

查看:131
本文介绍了iOS 7 UIPickerView非选定行曲率修改多个组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改UIPickerView曲率,使其看起来像iOS 7计时器。

I am trying to modify the UIPickerView curvature to look like the iOS 7 Timer.

这是我所拥有的:

Here is what I have:

注意2和4如何与选定行中的3。有没有办法让它更扁平,在iOS7中定时器,其中2和4直接位于3的上方和下方?

Note how the 2 and 4 are offset significantly from the 3 in the selected row. Is there a way to make it more 'flat', a la Timer in iOS7, where the 2 and 4 are directly above and below the 3?

这就是我的意思到目前为止已经尝试过:

Here is what I have tried so far:


  1. - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)组件

似乎无效。

任何帮助?

推荐答案

偏移是由选择器指示器所在的单独的凸起平面引起的。这实际上是对这种现实生活视角(嵌套,印刷,透明圆柱体)的相当准确的渲染。 Apple在Clock应用程序中的作用是右对齐拾取器标签。这确保了数字与其单位标签之间的间距保持不变。你可以做同样的事情。

The offset is due to the separate, raised plane on which the selector indicator lies. This is actually a fairly accurate rendering of such a real life perspective (of nested, printed, clear cylinders). What Apple does in the Clock app is to right align the picker labels. This ensures that the spacing between the number and its unit label remains constant. You can do the same thing.

首先,在你的选择器视图委托中你要实现 -pickerView:attributionTitleForRow:forComponent: in lieu of -pickerView:titleForRow:forComponent:。 (看起来你已经使用白色文本颜色完成了这项工作。)您将使用 NSParagraphStyle 字符串属性。您需要在段落样式上设置两个属性:alignment和tail indent。对齐应设置为 NSTextRightAlignment 。尾部对齐将取决于您希望标签从组件的右边缘坐多远。如果您有多个组件,则需要使用 -pickerView:widthForComponent:设置组件的宽度。如果要将曲率保持在最小值,请将组件宽度设置为尾部缩进的大约两倍。

First off, in your picker view delegate you want to implement -pickerView:attributedTitleForRow:forComponent: in lieu of -pickerView:titleForRow:forComponent:. (It looks like you’ve already done this given the white text color.) You will use the NSParagraphStyle string attribute. You will need to set two properties on the paragraph style: alignment and tail indent. The alignment should be set to NSTextRightAlignment. The tail alignment will depend on how far you want the labels to sit from the right edge of the component. If you have more than one component, you will need to set the width of the component using -pickerView:widthForComponent:. If you want to keep the curvature to a minimum, set the component width to approximately double the tail indent.

注意:如果你的选择器只有两个组件,每个组件的宽度必须小于选择器宽度的⅓。

NOTE: If your picker has exactly two components, the width of each component must be less than ⅓ the width of the picker.

这是一个代码示例:

- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setAlignment:NSTextAlignmentRight];
    [paragraphStyle setTailIndent:150];

    return [[NSAttributedString alloc] initWithString:@"42"
                                           attributes:@{NSParagraphStyleAttributeName:paragraphStyle}];
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
    return 300;
}

这篇关于iOS 7 UIPickerView非选定行曲率修改多个组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆