Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何将每行上的选择器视图标题文本向右对齐?_Iphone_Uipickerview - Fatal编程技术网

Iphone 如何将每行上的选择器视图标题文本向右对齐?

Iphone 如何将每行上的选择器视图标题文本向右对齐?,iphone,uipickerview,Iphone,Uipickerview,如何将UIPickerview中每行的标题向右对齐 提前感谢。您可以实现委托的pickerView:viewForRow:forComponent:reusingView:方法并从中返回UILabel实例: - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ UILa

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


提前感谢。

您可以实现委托的
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。但如果要更改标准行的外观,则必须创建自定义标签(或任何其他自定义视图)