sizes launchscreen guidelines ios fonts picker

launchscreen - ¿Cómo puedo cambiar la fuente de texto en UIPickerView en iOS 7?



ios splash screen (8)

Creo que debe agregar NSFontAttributeName en su lista de attributes y puede usar el método de clase fontWithName:size: de UIFont

Pude cambiar el color de mi fuente, pero también necesito cambiar el tamaño de la fuente, ¿cómo puedo lograr eso? Aquí está mi código para cambiar el color,

- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component { NSString *title = _currencyName[row]; NSAttributedString *attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}]; return attString; }

ACTUALIZACIÓN: esto no funcionó:

NSAttributedString *attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Light" size:40]}];


pickerView:viewForRow:forComponent:reusingView: implementar pickerView:viewForRow:forComponent:reusingView: method en delegado del selector

- (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; }


- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { UILabel* tView = (UILabel*)view; if (!tView) { tView = [[UILabel alloc] init]; [tView setFont:[UIFont fontWithName:@"Helvetica" size:14]]; //[tView setTextAlignment:UITextAlignmentLeft]; tView.numberOfLines=3; } // Fill the label text here tView.text=[wishvalues objectAtIndex:row]; return tView; }


Aquí está la versión Swift probada en iOS8:

Actualice en Swift para iOS8, puede agregar esto a su delegado:

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!; }


Gracias por @Richard Bown

¿Esta sería una mejor respuesta para Swift?

func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView { if let titleLabel = view as? UILabel { titleLabel.text = "Your Text" return titleLabel } else { let titleLabel = UILabel() titleLabel.font = UIFont.boldSystemFontOfSize(16)//Font you want here titleLabel.textAlignment = NSTextAlignment.Center titleLabel.text = "Your Text" return titleLabel } }


Puede usar el siguiente código para establecer la fuente de pickerview ..

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { UILabel *tView = (UILabel *)view; if (!tView){ tView = [[UILabel alloc] init]; [tView setFont:[UIFont .....]];//set font // Setup label properties - frame, font, colors etc ... } // Fill the label text here ... return tView; }


let textLabel = view as? UILabel ?? { let label = UILabel() label.font = UIFont.boldSystemFontOfSize(16) label.textAlignment = .Center return label }() textLabel.text = Array(componentDataSources[component].keys)[row] return textLabel


Actualizado para Swift 4:

public func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView { let label = view as? UILabel ?? UILabel() label.font = .systemFont(ofSize: 16) label.textColor = .white label.textAlignment = .center label.text = text(for: row, for: component) return label }