How to set the text alignment in picker view iOS

前端 未结 4 1188
臣服心动
臣服心动 2021-01-20 22:21

I need to set the alignment of the text in picker view but my solutions doesn\'t work. This is my code so far. I used array to store values on the picker view.



        
4条回答
  •  爱一瞬间的悲伤
    2021-01-20 22:46

    i done with this code for UIlabel text show in center of tableView like:-

    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
    {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 37)];
    
            if (component == 0) {
    
                label.font=[UIFont boldSystemFontOfSize:22];
                label.textAlignment = UITextAlignmentCenter;
                label.backgroundColor = [UIColor clearColor];
    
            label.text = [NSString stringWithFormat:@"%@", [source objectAtIndex:row]];
            label.font=[UIFont boldSystemFontOfSize:22];
    
            }
        [label autorelease];
        return label;
     }
    

    Code output is

    enter image description here

提交回复
热议问题