Jon*_*Jon 8 uipickerview ios ios7
我试图修改UIPickerView曲率看起来像iOS 7计时器.
这是我有的:
注意2和4如何与所选行中的3显着偏移.有没有办法让它变得更"扁平",在iOS7中是一个定时器,其中2和4直接位于3的上方和下方?
这是我到目前为止所尝试的:
玩弄 - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
使用自定义UIView和自定义UILabel偏移量
似乎没有工作.
有帮助吗?
偏移是由选择器指示器所在的单独的凸起平面引起的.这实际上是对这种现实生活视角(嵌套,印刷,透明圆柱体)的相当准确的渲染.Apple在Clock应用程序中的作用是右对齐拾取器标签.这确保了数字与其单位标签之间的间距保持不变.你可以做同样的事情.
首先,在你的选择器视图委托中你要实现-pickerView:attributionTitleForRow:forComponent:代替-pickerView:titleForRow:forComponent : . (看起来你已经用白色文本颜色完成了这个.)你将使用NSParagraphStyle字符串属性.您需要在段落样式上设置两个属性:alignment和tail indent.对齐应设置为NSTextRightAlignment.尾部对齐将取决于您希望标签从组件的右边缘坐多远.如果您有多个组件,则需要使用-pickerView:widthForComponent:设置组件的宽度.如果要将曲率保持在最小值,请将组件宽度设置为尾部缩进的大约两倍.
注意:如果拾取器只有两个组件,则每个组件的宽度必须小于拾取器宽度的1/3.
这是一个代码示例:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7299 次 |
最近记录: |