How can I change text font in UIPickerView in iOS 7?

前端 未结 8 1587
清酒与你
清酒与你 2020-12-09 14:55

I was able to change my font color but I also need to change font size, how can I accomplish that? Here\'s my code for chaning the color,

 - (NSAttributedStr         


        
8条回答
  •  时光取名叫无心
    2020-12-09 15:22

    You need to implement pickerView:viewForRow:forComponent:reusingView: method in picker's delegate

    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
        UILabel* lbl = (UILabel*)view;
        // Customise Font 
        if (lbl == nil) {
              //label size
              CGRect frame = CGRectMake(0.0, 0.0, 70, 30);
    
              lbl = [[UILabel alloc] initWithFrame:frame];
    
              [lbl setTextAlignment:UITextAlignmentLeft];
    
              [lbl setBackgroundColor:[UIColor clearColor]];
               //here you can play with fonts
              [lbl setFont:[UIFont fontWithName:@"Times New Roman" size:14.0]];
    
       }
          //picker view array is the datasource
       [lbl setText:[pickerViewArray objectAtIndex:row]];
    
    
            return lbl;
    }
    

提交回复
热议问题