I have a button that I use custom UIFont to display text on. The font loads correctly and is correctly applied to the button title. My problem is I can't seem to be able to change font size:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(loginButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Login" forState:UIControlStateNormal];
button.frame = CGRectMake(63.0, 200.0, 194.0, 60.0);
button.titleLabel.font = [UIFont fontWithName:@"My-Font" size:8.0f];
[self.view addSubview:button];
No matter what I put in for font size, I get some default size. On the other hand, if I do something like this:
button.titleLabel.font = [UIFont systemFontOfSize:32.0f];
I get size 32 font, however, of course, I don't get my custom font. So, how do I set a size for custom font?
(I use Xcode 4.6.3)
To change the font or the size of a UILabel in a Storyboard or . XIB file, open it in the interface builder. Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.
Seems like your UIFont object isn't getting created correctly and is returning nil
.
This is the best tutorial I have found on putting in custom fonts. Good luck ;)
http://refactr.com/blog/2012/09/ios-tips-custom-fonts/ (Archived Version)
To get the font name you have to pass in fontWithName:size:
, open your font with Font Book app, then look up for the PostScript name
property. Make shure you have added it to Info.plist
file too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With