Comment puis-je changer la police du texte dans UIPickerView dans iOS 7?
J'ai pu changer ma couleur de police, mais j'ai aussi besoin de changer la taille de police, comment puis-je le réaliser? Voici mon code pour chaning la couleur,
- (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;
}
Mise à JOUR: cela n'a pas fonctionné:
NSAttributedString *attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Light" size:40]}];
Vous devez vous connecter pour publier un commentaire.
Voici la Swift version testée sur iOS8:
Mise à jour rapide pour iOS8, vous pouvez ajouter ceci à votre délégué:
Vous avez besoin pour mettre en œuvre
pickerView:viewForRow:forComponent:reusingView:
méthode du sélecteur de déléguéMis à jour pour Swift 4:
Vous pouvez utiliser le code suivant pour définir la police de pickerview..
Merci pour @Richard Bown
Serait-ce une meilleure solution pour Swift?
Je pense que vous devez ajouter
NSFontAttributeName
dans votre liste deattributes
et vous pouvez utiliser la méthode de la classefontWithName:size:
deUIFont
[attString addAttribute:NSFontAttributeName value:/*your font*/ range:NSMakeRange(0, attString.length)];
NSAttributedString
pourNSMutableAttributedString