How to change font size in UIPickerView?

I have one UIPickerView. It has about 200 points, each subject has long texts, therefore, I want to change the font size of the UIPickerView. How can I change it? Maybe? Can someone help me? Thank!

Yuva.M

+43
iphone font-size uipickerview
Aug 25 '11 at 5:14
source share
7 answers

You need to implement the pickerView:viewForRow:forComponent:reusingView: method in the collector delegate

 - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ UILabel* tView = (UILabel*)view; if (!tView){ tView = [[UILabel alloc] init]; // Setup label properties - frame, font, colors etc ... } // Fill the label text here ... return tView; } 
+84
Aug 25 '11 at 5:17
source share

Update in Swift for iOS8, you can add this to your delegate:

 func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView { var pickerLabel = view as? UILabel; if (pickerLabel == nil) { pickerLabel = UILabel() pickerLabel?.font = UIFont(name: "Montserrat", size: 16) pickerLabel?.textAlignment = NSTextAlignment.Center } pickerLabel?.text = fetchLabelForRowNumber(row) return pickerLabel!; } 
+21
Jul 19 '15 at 11:04
source share



To customize the font of strings UIPickerView

 - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { UILabel* pickerLabel = (UILabel*)view; if (!pickerLabel) { pickerLabel = [[UILabel alloc] init]; pickerLabel.font = [UIFont fontWithName:@"SourceSansPro-Semibold" size:16]; pickerLabel.textAlignment=NSTextAlignmentCenter; } [pickerLabel setText:[self.data objectAtIndex:row]]; return pickerLabel; } 
+11
May 18 '15 at 5:51
source share

Try it, this should help:

  - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ UILabel* tView = (UILabel*)view; if (!tView){ tView = [[UILabel alloc] init]; // Setup label properties - frame, font, colors etc ... //adjustsFontSizeToFitWidth property to YES tView.minimumFontSize = 8.; tView.adjustsFontSizeToFitWidth = YES; } // Fill the label text here ... return tView; } // altro modo completo sembrerebbe... - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { UILabel *pickerLabel = (UILabel *)view; if (pickerLabel == nil) { CGRect frame = CGRectMake(0.0, 0.0, 80, 32); pickerLabel = [[[UILabel alloc] initWithFrame:frame] autorelease]; [pickerLabel setTextAlignment:UITextAlignmentLeft]; [pickerLabel setBackgroundColor:[UIColor clearColor]]; [pickerLabel setFont:[UIFont boldSystemFontOfSize:15]]; } [pickerLabel setText:[pickerDataArray objectAtIndex:row]]; return pickerLabel; } 
+7
01 Sep
source share

Swift 3 | Autoshrink

Set adjustsFontSizeToFitWidth=true and minimumScaleFactor=0.5

 func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView { var label: UILabel if let view = view as? UILabel { label = view } else { label = UILabel() } label.text = "My Picker Text" label.textAlignment = .center label.font = UIFont.boldSystemFont(ofSize: 20) label.adjustsFontSizeToFitWidth = true label.minimumScaleFactor = 0.5 return label } 
+2
Apr 21 '17 at 18:28
source share

For goal c

 - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ UILabel* pickerLabel = (UILabel*)view; if (!pickerLabel){ pickerLabel = [[UILabel alloc] init]; // Setup label properties - frame, font, colors etc [pickerLabel setFont:[UIFont fontWithName:LATO_REGULAR_FONT size:SIZE_SEMIBOLD_FONT]]; pickerLabel.textColor = primaryTextColor; pickerLabel.textAlignment = NSTextAlignmentCenter; } // Fill the label text here pickerLabel.text = self.dataSourceArray[row]; return pickerLabel; } 

For Swift 2.3

  func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView{ var label = view as! UILabel! if label == nil { label = UILabel() } label.font = LATO_REGULAR_FONT_17 label.text = dataArray[row] as? String label.textAlignment = .Center return label } 
0
Feb 17 '17 at 5:47
source share

Swift 4.x

 func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView { var label = UILabel() if let v = view { label = v as! UILabel } label.font = UIFont (name: "Helvetica Neue", size: 10) label.text = dataArray[row] label.textAlignment = .center return label } 
0
Nov 02 '17 at 10:43 on
source share



All Articles