【问题标题】:How to align picker view title text on each row to the right?如何将每行上的选择器视图标题文本向右对齐?
【发布时间】:2010-05-03 05:33:24
【问题描述】:

如何将 UIPickerview 中每一行的标题向右对齐?

提前致谢。

【问题讨论】:

    标签: iphone uipickerview


    【解决方案1】:

    您可以实现委托的pickerView:viewForRow:forComponent:reusingView: 方法并从中返回 UILabel 实例:

    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
        UILabel* label = (UILabel*)view;
        if (view == nil){
           label= [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 190, 44)];
    
           label.textAlignment = UITextAlignmentRight;
           //Set other properties if you need like font, text color etc
           ...
        }
        label.text = [self textForRow:row forComponent:component];
        return label;
    }
    

    【讨论】:

    • 我们可以将此mentod 与titleForRow:forComponent 结合使用吗?
    • @Ans,当然,您可以在代码中从 pickerView:viewForRow:forComponent:reusingView: 调用 titleForRow:forComponent:。但是如果你想改变标准行的外观,你必须创建自定义标签(或任何其他自定义视图)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-30
    • 1970-01-01
    • 2012-01-27
    • 2021-06-13
    相关资源
    最近更新 更多