let attributes: [NSAttributedStringKey : Any] = [NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.font: UIFont(name: "Menlo", size: 17.0) ?? UIFont.systemFont(ofSize: 17.0) ] textField.attributedPlaceholder = NSAttributedString(string: "Placeholder Text", attributes: attributes)
Note: when we use the UIFont method (name: "Menlo", size: 17.0), if the font name cannot get it in ios, then it will be null, so we need to provide a default font. This has been explained above.
You can use the code below. First, find the name of the system-accepted font for your custom font.
for (NSString *familyName in [UIFont familyNames]) { for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) { NSLog(@"%@", fontName); } }
Jack Long Jul 14 '17 at 1:31 on 2017-07-14 01:31
source share