iphone - 如何将每行上的选择器 View 标题文本向右对齐?

标签 iphone uipickerview

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

提前致谢。

最佳答案

您可以实现委托(delegate)的 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;
}

关于iphone - 如何将每行上的选择器 View 标题文本向右对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2756286/

相关文章:

swift - UIPickerView 没有在 UITextField 中选择日期

iphone - 删除了Team Provisioning Profile :* in the Provisioning Portal,怎么办?

iphone - 什么时候在 iOS 中使用 CoreData 显式保存?

objective-c - UIPickerView 在滚动之前不会重新加载

ios - UIPickerView 选择指示器在 iOS10 中不可见

iphone - 多个 UIPickerView

iphone - 如何从左到右更改 UIPickerView 中的文本

iphone - 获取服务器 iPhone 上目录中的文件列表

iphone - 来自 iPhone 的 cURL 网络服务

ios - 禁用 CPPickerView 不起作用