[objective-c] Set UIButton title UILabel font size programmatically

I need to set the font size of the title UILabel of a UIButton programmatically.

This question is related to objective-c cocoa-touch ios uibutton font-size

The answer is


You can also set the font size, and the font style using something like this. It's a little more than what you're asking for but hey, what the heck...

[myButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:13.0]];

And… if you're feeling frisky a list of available fonts can be found by implementing this code and then checking the output in your xCode debugger.

Code:

NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
    NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
    fontNames = [[NSArray alloc] initWithArray:
            [UIFont fontNamesForFamilyName:
            [familyNames objectAtIndex:indFamily]]];
    for (indFont=0; indFont<[fontNames count]; ++indFont)
    {
        NSLog(@"    Font name: %@", [fontNames objectAtIndex:indFont]);
    }
}

Example:

2012-04-02 11:36:34.395 MyApp[3579:707] Family name: Thonburi
2012-04-02 11:36:34.398 MyApp[3579:707]     Font name: Thonburi-Bold
2012-04-02 11:36:34.402 MyApp[3579:707]     Font name: Thonburi
2012-04-02 11:36:34.405 MyApp[3579:707] Family name: Snell Roundhand
2012-04-02 11:36:34.408 MyApp[3579:707]     Font name: SnellRoundhand-Bold
2012-04-02 11:36:34.411 MyApp[3579:707]     Font name: SnellRoundhand-Black
2012-04-02 11:36:34.415 MyApp[3579:707]     Font name: SnellRoundhand
2012-04-02 11:36:34.418 MyApp[3579:707] Family name: Academy Engraved LET
2012-04-02 11:36:34.421 MyApp[3579:707]     Font name: AcademyEngravedLetPlain
2012-04-02 11:36:34.424 MyApp[3579:707] Family name: Marker Felt
2012-04-02 11:36:34.427 MyApp[3579:707]     Font name: MarkerFelt-Wide
2012-04-02 11:36:34.430 MyApp[3579:707]     Font name: MarkerFelt-Thin
2012-04-02 11:36:34.434 MyApp[3579:707] Family name: Geeza Pro
2012-04-02 11:36:34.437 MyApp[3579:707]     Font name: GeezaPro-Bold
2012-04-02 11:36:34.441 MyApp[3579:707]     Font name: GeezaPro
2012-04-02 11:36:34.445 MyApp[3579:707] Family name: Arial Rounded MT Bold
2012-04-02 11:36:34.448 MyApp[3579:707]     Font name: ArialRoundedMTBold
2012-04-02 11:36:34.451 MyApp[3579:707] Family name: Trebuchet MS
2012-04-02 11:36:34.455 MyApp[3579:707]     Font name: TrebuchetMS
2012-04-02 11:36:34.458 MyApp[3579:707]     Font name: TrebuchetMS-Bold
2012-04-02 11:36:34.461 MyApp[3579:707]     Font name: TrebuchetMS-Italic
2012-04-02 11:36:34.464 MyApp[3579:707]     Font name: Trebuchet-BoldItalic
2012-04-02 11:36:34.467 MyApp[3579:707] Family name: Arial
2012-04-02 11:36:34.471 MyApp[3579:707]     Font name: Arial-BoldMT
2012-04-02 11:36:34.474 MyApp[3579:707]     Font name: ArialMT
2012-04-02 11:36:34.477 MyApp[3579:707]     Font name: Arial-ItalicMT
2012-04-02 11:36:34.480 MyApp[3579:707]     Font name: Arial-BoldItalicMT
2012-04-02 11:36:34.483 MyApp[3579:707] Family name: Marion
2012-04-02 11:36:34.487 MyApp[3579:707]     Font name: Marion-Regular
2012-04-02 11:36:34.491 MyApp[3579:707]     Font name: Marion-Bold
2012-04-02 11:36:34.494 MyApp[3579:707]     Font name: Marion-Italic
2012-04-02 11:36:34.503 MyApp[3579:707] Family name: Gurmukhi MN
2012-04-02 11:36:34.507 MyApp[3579:707]     Font name: GurmukhiMN
2012-04-02 11:36:34.511 MyApp[3579:707]     Font name: GurmukhiMN-Bold
2012-04-02 11:36:34.514 MyApp[3579:707] Family name: Malayalam Sangam MN
2012-04-02 11:36:34.518 MyApp[3579:707]     Font name: MalayalamSangamMN-Bold
2012-04-02 11:36:34.522 MyApp[3579:707]     Font name: MalayalamSangamMN
2012-04-02 11:36:34.525 MyApp[3579:707] Family name: Bradley Hand
2012-04-02 11:36:34.529 MyApp[3579:707]     Font name: BradleyHandITCTT-Bold
2012-04-02 11:36:34.532 MyApp[3579:707] Family name: Kannada Sangam MN
2012-04-02 11:36:34.536 MyApp[3579:707]     Font name: KannadaSangamMN
2012-04-02 11:36:34.540 MyApp[3579:707]     Font name: KannadaSangamMN-Bold
2012-04-02 11:36:34.544 MyApp[3579:707] Family name: Bodoni 72 Oldstyle
2012-04-02 11:36:34.548 MyApp[3579:707]     Font name: BodoniSvtyTwoOSITCTT-Book
2012-04-02 11:36:34.552 MyApp[3579:707]     Font name: BodoniSvtyTwoOSITCTT-Bold
2012-04-02 11:36:34.555 MyApp[3579:707]     Font name: BodoniSvtyTwoOSITCTT-BookIt
2012-04-02 11:36:34.559 MyApp[3579:707] Family name: Cochin
2012-04-02 11:36:34.562 MyApp[3579:707]     Font name: Cochin
2012-04-02 11:36:34.566 MyApp[3579:707]     Font name: Cochin-BoldItalic
2012-04-02 11:36:34.570 MyApp[3579:707]     Font name: Cochin-Italic
2012-04-02 11:36:34.573 MyApp[3579:707]     Font name: Cochin-Bold
2012-04-02 11:36:34.577 MyApp[3579:707] Family name: Sinhala Sangam MN
2012-04-02 11:36:34.581 MyApp[3579:707]     Font name: SinhalaSangamMN
2012-04-02 11:36:34.584 MyApp[3579:707]     Font name: SinhalaSangamMN-Bold
2012-04-02 11:36:34.588 MyApp[3579:707] Family name: Hiragino Kaku Gothic ProN
2012-04-02 11:36:34.592 MyApp[3579:707]     Font name: HiraKakuProN-W6
2012-04-02 11:36:34.596 MyApp[3579:707]     Font name: HiraKakuProN-W3
2012-04-02 11:36:34.599 MyApp[3579:707] Family name: Papyrus
2012-04-02 11:36:34.603 MyApp[3579:707]     Font name: Papyrus-Condensed
2012-04-02 11:36:34.607 MyApp[3579:707]     Font name: Papyrus
2012-04-02 11:36:34.614 MyApp[3579:707] Family name: Verdana
2012-04-02 11:36:34.620 MyApp[3579:707]     Font name: Verdana
2012-04-02 11:36:34.626 MyApp[3579:707]     Font name: Verdana-Bold
2012-04-02 11:36:34.674 MyApp[3579:707]     Font name: Verdana-BoldItalic
2012-04-02 11:36:34.690 MyApp[3579:707]     Font name: Verdana-Italic
2012-04-02 11:36:34.730 MyApp[3579:707] Family name: Zapf Dingbats
2012-04-02 11:36:34.748 MyApp[3579:707]     Font name: ZapfDingbatsITC
2012-04-02 11:36:34.752 MyApp[3579:707] Family name: Courier
2012-04-02 11:36:34.757 MyApp[3579:707]     Font name: Courier-Bold
2012-04-02 11:36:34.762 MyApp[3579:707]     Font name: Courier
2012-04-02 11:36:34.769 MyApp[3579:707]     Font name: Courier-BoldOblique
2012-04-02 11:36:34.778 MyApp[3579:707]     Font name: Courier-Oblique
2012-04-02 11:36:34.786 MyApp[3579:707] Family name: Hoefler Text
2012-04-02 11:36:34.793 MyApp[3579:707]     Font name: HoeflerText-Black
2012-04-02 11:36:34.802 MyApp[3579:707]     Font name: HoeflerText-Italic
2012-04-02 11:36:34.810 MyApp[3579:707]     Font name: HoeflerText-Regular
2012-04-02 11:36:34.819 MyApp[3579:707]     Font name: HoeflerText-BlackItalic
2012-04-02 11:36:34.827 MyApp[3579:707] Family name: Euphemia UCAS
2012-04-02 11:36:34.836 MyApp[3579:707]     Font name: EuphemiaUCAS-Bold
2012-04-02 11:36:34.843 MyApp[3579:707]     Font name: EuphemiaUCAS
2012-04-02 11:36:34.848 MyApp[3579:707]     Font name: EuphemiaUCAS-Italic
2012-04-02 11:36:34.853 MyApp[3579:707] Family name: Helvetica
2012-04-02 11:36:34.857 MyApp[3579:707]     Font name: Helvetica-LightOblique
2012-04-02 11:36:34.863 MyApp[3579:707]     Font name: Helvetica
2012-04-02 11:36:34.873 MyApp[3579:707]     Font name: Helvetica-Oblique
2012-04-02 11:36:34.876 MyApp[3579:707]     Font name: Helvetica-BoldOblique
2012-04-02 11:36:34.880 MyApp[3579:707]     Font name: Helvetica-Bold
2012-04-02 11:36:34.884 MyApp[3579:707]     Font name: Helvetica-Light
2012-04-02 11:36:34.887 MyApp[3579:707] Family name: Hiragino Mincho ProN
2012-04-02 11:36:34.892 MyApp[3579:707]     Font name: HiraMinProN-W3
2012-04-02 11:36:34.898 MyApp[3579:707]     Font name: HiraMinProN-W6
2012-04-02 11:36:34.902 MyApp[3579:707] Family name: Bodoni Ornaments
2012-04-02 11:36:34.905 MyApp[3579:707]     Font name: BodoniOrnamentsITCTT
2012-04-02 11:36:34.923 MyApp[3579:707] Family name: Apple Color Emoji
2012-04-02 11:36:34.938 MyApp[3579:707]     Font name: AppleColorEmoji
2012-04-02 11:36:34.942 MyApp[3579:707] Family name: Optima
2012-04-02 11:36:34.946 MyApp[3579:707]     Font name: Optima-ExtraBlack
2012-04-02 11:36:34.950 MyApp[3579:707]     Font name: Optima-Italic
2012-04-02 11:36:34.954 MyApp[3579:707]     Font name: Optima-Regular
2012-04-02 11:36:34.965 MyApp[3579:707]     Font name: Optima-BoldItalic
2012-04-02 11:36:34.969 MyApp[3579:707]     Font name: Optima-Bold
2012-04-02 11:36:34.972 MyApp[3579:707] Family name: Gujarati Sangam MN
2012-04-02 11:36:34.985 MyApp[3579:707]     Font name: GujaratiSangamMN
2012-04-02 11:36:34.989 MyApp[3579:707]     Font name: GujaratiSangamMN-Bold
2012-04-02 11:36:34.993 MyApp[3579:707] Family name: Devanagari Sangam MN
2012-04-02 11:36:34.998 MyApp[3579:707]     Font name: DevanagariSangamMN
2012-04-02 11:36:35.002 MyApp[3579:707]     Font name: DevanagariSangamMN-Bold
2012-04-02 11:36:35.006 MyApp[3579:707] Family name: Times New Roman
2012-04-02 11:36:35.017 MyApp[3579:707]     Font name: TimesNewRomanPS-ItalicMT
2012-04-02 11:36:35.021 MyApp[3579:707]     Font name: TimesNewRomanPS-BoldMT
2012-04-02 11:36:35.032 MyApp[3579:707]     Font name: TimesNewRomanPSMT
2012-04-02 11:36:35.037 MyApp[3579:707]     Font name: TimesNewRomanPS-BoldItalicMT
2012-04-02 11:36:35.041 MyApp[3579:707] Family name: Kailasa
2012-04-02 11:36:35.045 MyApp[3579:707]     Font name: Kailasa
2012-04-02 11:36:35.050 MyApp[3579:707]     Font name: Kailasa-Bold
2012-04-02 11:36:35.053 MyApp[3579:707] Family name: Telugu Sangam MN
2012-04-02 11:36:35.064 MyApp[3579:707]     Font name: TeluguSangamMN-Bold
2012-04-02 11:36:35.068 MyApp[3579:707]     Font name: TeluguSangamMN
2012-04-02 11:36:35.071 MyApp[3579:707] Family name: Heiti SC
2012-04-02 11:36:35.099 MyApp[3579:707]     Font name: STHeitiSC-Medium
2012-04-02 11:36:35.107 MyApp[3579:707]     Font name: STHeitiSC-Light
2012-04-02 11:36:35.111 MyApp[3579:707] Family name: Futura
2012-04-02 11:36:35.115 MyApp[3579:707]     Font name: Futura-Medium
2012-04-02 11:36:35.119 MyApp[3579:707]     Font name: Futura-CondensedExtraBold
2012-04-02 11:36:35.122 MyApp[3579:707]     Font name: Futura-CondensedMedium
2012-04-02 11:36:35.135 MyApp[3579:707]     Font name: Futura-MediumItalic
2012-04-02 11:36:35.155 MyApp[3579:707] Family name: Bodoni 72
2012-04-02 11:36:35.160 MyApp[3579:707]     Font name: BodoniSvtyTwoITCTT-BookIta
2012-04-02 11:36:35.164 MyApp[3579:707]     Font name: BodoniSvtyTwoITCTT-Book
2012-04-02 11:36:35.168 MyApp[3579:707]     Font name: BodoniSvtyTwoITCTT-Bold
2012-04-02 11:36:35.171 MyApp[3579:707] Family name: Baskerville
2012-04-02 11:36:35.183 MyApp[3579:707]     Font name: Baskerville-SemiBoldItalic
2012-04-02 11:36:35.187 MyApp[3579:707]     Font name: Baskerville-Bold
2012-04-02 11:36:35.197 MyApp[3579:707]     Font name: Baskerville-Italic
2012-04-02 11:36:35.245 MyApp[3579:707]     Font name: Baskerville-BoldItalic
2012-04-02 11:36:35.253 MyApp[3579:707]     Font name: Baskerville-SemiBold
2012-04-02 11:36:35.258 MyApp[3579:707]     Font name: Baskerville
2012-04-02 11:36:35.262 MyApp[3579:707] Family name: Chalkboard SE
2012-04-02 11:36:35.266 MyApp[3579:707]     Font name: ChalkboardSE-Regular
2012-04-02 11:36:35.269 MyApp[3579:707]     Font name: ChalkboardSE-Bold
2012-04-02 11:36:35.279 MyApp[3579:707]     Font name: ChalkboardSE-Light
2012-04-02 11:36:35.284 MyApp[3579:707] Family name: Heiti TC
2012-04-02 11:36:35.288 MyApp[3579:707]     Font name: STHeitiTC-Medium
2012-04-02 11:36:35.299 MyApp[3579:707]     Font name: STHeitiTC-Light
2012-04-02 11:36:35.305 MyApp[3579:707] Family name: Copperplate
2012-04-02 11:36:35.310 MyApp[3579:707]     Font name: Copperplate
2012-04-02 11:36:35.313 MyApp[3579:707]     Font name: Copperplate-Light
2012-04-02 11:36:35.317 MyApp[3579:707]     Font name: Copperplate-Bold
2012-04-02 11:36:35.320 MyApp[3579:707] Family name: Party LET
2012-04-02 11:36:35.334 MyApp[3579:707]     Font name: PartyLetPlain
2012-04-02 11:36:35.338 MyApp[3579:707] Family name: American Typewriter
2012-04-02 11:36:35.351 MyApp[3579:707]     Font name: AmericanTypewriter-CondensedLight
2012-04-02 11:36:35.357 MyApp[3579:707]     Font name: AmericanTypewriter-Light
2012-04-02 11:36:35.361 MyApp[3579:707]     Font name: AmericanTypewriter-Bold
2012-04-02 11:36:35.364 MyApp[3579:707]     Font name: AmericanTypewriter
2012-04-02 11:36:35.368 MyApp[3579:707]     Font name: AmericanTypewriter-CondensedBold
2012-04-02 11:36:35.372 MyApp[3579:707]     Font name: AmericanTypewriter-Condensed
2012-04-02 11:36:35.384 MyApp[3579:707] Family name: AppleGothic
2012-04-02 11:36:35.400 MyApp[3579:707]     Font name: AppleGothic
2012-04-02 11:36:35.406 MyApp[3579:707] Family name: Bangla Sangam MN
2012-04-02 11:36:35.411 MyApp[3579:707]     Font name: BanglaSangamMN-Bold
2012-04-02 11:36:35.414 MyApp[3579:707]     Font name: BanglaSangamMN
2012-04-02 11:36:35.418 MyApp[3579:707] Family name: Noteworthy
2012-04-02 11:36:35.422 MyApp[3579:707]     Font name: Noteworthy-Light
2012-04-02 11:36:35.432 MyApp[3579:707]     Font name: Noteworthy-Bold
2012-04-02 11:36:35.436 MyApp[3579:707] Family name: Zapfino
2012-04-02 11:36:35.443 MyApp[3579:707]     Font name: Zapfino
2012-04-02 11:36:35.448 MyApp[3579:707] Family name: Tamil Sangam MN
2012-04-02 11:36:35.452 MyApp[3579:707]     Font name: TamilSangamMN
2012-04-02 11:36:35.456 MyApp[3579:707]     Font name: TamilSangamMN-Bold
2012-04-02 11:36:35.459 MyApp[3579:707] Family name: DB LCD Temp
2012-04-02 11:36:35.463 MyApp[3579:707]     Font name: DBLCDTempBlack
2012-04-02 11:36:35.467 MyApp[3579:707] Family name: Arial Hebrew
2012-04-02 11:36:35.471 MyApp[3579:707]     Font name: ArialHebrew
2012-04-02 11:36:35.475 MyApp[3579:707]     Font name: ArialHebrew-Bold
2012-04-02 11:36:35.479 MyApp[3579:707] Family name: Chalkduster
2012-04-02 11:36:35.482 MyApp[3579:707]     Font name: Chalkduster
2012-04-02 11:36:35.486 MyApp[3579:707] Family name: Georgia
2012-04-02 11:36:35.490 MyApp[3579:707]     Font name: Georgia-Italic
2012-04-02 11:36:35.493 MyApp[3579:707]     Font name: Georgia-BoldItalic
2012-04-02 11:36:35.497 MyApp[3579:707]     Font name: Georgia-Bold
2012-04-02 11:36:35.501 MyApp[3579:707]     Font name: Georgia
2012-04-02 11:36:35.504 MyApp[3579:707] Family name: Helvetica Neue
2012-04-02 11:36:35.508 MyApp[3579:707]     Font name: HelveticaNeue-Bold
2012-04-02 11:36:35.511 MyApp[3579:707]     Font name: HelveticaNeue-CondensedBlack
2012-04-02 11:36:35.515 MyApp[3579:707]     Font name: HelveticaNeue-Medium
2012-04-02 11:36:35.518 MyApp[3579:707]     Font name: HelveticaNeue
2012-04-02 11:36:35.522 MyApp[3579:707]     Font name: HelveticaNeue-Light
2012-04-02 11:36:35.526 MyApp[3579:707]     Font name: HelveticaNeue-CondensedBold
2012-04-02 11:36:35.529 MyApp[3579:707]     Font name: HelveticaNeue-LightItalic
2012-04-02 11:36:35.532 MyApp[3579:707]     Font name: HelveticaNeue-UltraLightItalic
2012-04-02 11:36:35.536 MyApp[3579:707]     Font name: HelveticaNeue-UltraLight
2012-04-02 11:36:35.540 MyApp[3579:707]     Font name: HelveticaNeue-BoldItalic
2012-04-02 11:36:35.543 MyApp[3579:707]     Font name: HelveticaNeue-Italic
2012-04-02 11:36:35.547 MyApp[3579:707] Family name: Gill Sans
2012-04-02 11:36:35.551 MyApp[3579:707]     Font name: GillSans-LightItalic
2012-04-02 11:36:35.555 MyApp[3579:707]     Font name: GillSans-BoldItalic
2012-04-02 11:36:35.558 MyApp[3579:707]     Font name: GillSans-Italic
2012-04-02 11:36:35.562 MyApp[3579:707]     Font name: GillSans
2012-04-02 11:36:35.565 MyApp[3579:707]     Font name: GillSans-Bold
2012-04-02 11:36:35.569 MyApp[3579:707]     Font name: GillSans-Light
2012-04-02 11:36:35.572 MyApp[3579:707] Family name: Palatino
2012-04-02 11:36:35.576 MyApp[3579:707]     Font name: Palatino-Roman
2012-04-02 11:36:35.580 MyApp[3579:707]     Font name: Palatino-Bold
2012-04-02 11:36:35.583 MyApp[3579:707]     Font name: Palatino-BoldItalic
2012-04-02 11:36:35.587 MyApp[3579:707]     Font name: Palatino-Italic
2012-04-02 11:36:35.591 MyApp[3579:707] Family name: Courier New
2012-04-02 11:36:35.594 MyApp[3579:707]     Font name: CourierNewPSMT
2012-04-02 11:36:35.598 MyApp[3579:707]     Font name: CourierNewPS-BoldMT
2012-04-02 11:36:35.601 MyApp[3579:707]     Font name: CourierNewPS-BoldItalicMT
2012-04-02 11:36:35.605 MyApp[3579:707]     Font name: CourierNewPS-ItalicMT
2012-04-02 11:36:35.608 MyApp[3579:707] Family name: Oriya Sangam MN
2012-04-02 11:36:35.612 MyApp[3579:707]     Font name: OriyaSangamMN-Bold
2012-04-02 11:36:35.616 MyApp[3579:707]     Font name: OriyaSangamMN
2012-04-02 11:36:35.619 MyApp[3579:707] Family name: Didot
2012-04-02 11:36:35.623 MyApp[3579:707]     Font name: Didot-Italic
2012-04-02 11:36:35.627 MyApp[3579:707]     Font name: Didot
2012-04-02 11:36:35.630 MyApp[3579:707]     Font name: Didot-Bold
2012-04-02 11:36:35.634 MyApp[3579:707] Family name: Bodoni 72 Smallcaps
2012-04-02 11:36:35.638 MyApp[3579:707]     Font name: BodoniSvtyTwoSCITCTT-Book

Swift:

shareButton.titleLabel?.font = UIFont.systemFontOfSize(size)

Unimportant note: deleted by animuson? Dec 5 '14 at 16:48
animuson, I had the same problem now a month after I posted this answer. I was googling and found out this post which wasn't easily copy pastable into a swift project. While I was scrolling saw my deleted answer and copied it. so please don't delete actually useful stuff..


This would be helpful

button.titleLabel.font = [UIFont fontWithName:@"YOUR FONTNAME" size:12.0f]

you can also customise button font with bold, italic. this example with bold system font size.

[LoginButton.titleLabel setFont:[UIFont boldSystemFontOfSize:15.0f*Ratio]];

[button setFont:...] has been deprecated.

Use [button.titleLabel setFont:...] instead, for example:

[myButton.titleLabel setFont:[UIFont systemFontOfSize:10]];


Swift 5.

uiButton.titleLabel?.font = UIFont.systemFont(ofSize: 32)

This way you can set the fontSize and can handle it in just one class.

1. Created an extension of UIButton and added following code:

- (void)awakeFromNib{

    [super awakeFromNib];

    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.titleLabel setFont:[UIFont fontWithName:@"font" 
                                     size:self.titleLabel.font.pointSize]];
    [self setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
}

2.1 Create UIButton inside Code

Now if you create a UIButton inside your code, #import the extension of yourUIButton` and create the Button.

2.2 Create Button in Interface Builder

If you create the UIButton inside the Interface Builder, select the UIButton, go to the Identity Inspector and add the created extension as class for the UIButton.


You can use:

button.titleLabel.font = [UIFont systemFontOfSize:14.0];

Swift 4

button.titleLabel?.font = UIFont(name: "Font_Name_Here", size: Font_Size_Here)

Objective-c

[button.titleLabel setFont:[UIFont fontWithName:@“Font_Name_Here” size: Font_Size_Here]];

Example:

Font_Name = "Helvetica"

Font_Size = 16.0

Hope it helps.


Swift 3:

myButton.titleLabel?.font = myButton.titleLabel?.font.withSize(40)

swift 4.x

button.titleLabel?.font = UIFont.systemFont(ofSize: 20)

This should get you going

[btn_submit.titleLabel setFont:[UIFont systemFontOfSize:14.0f]];

this may help :

[objBtn.titleLabel setFont:[UIFont fontWithName:@“fontname” size:fontsize]];

I hope it will be help to you

[_button.titleLabel setFont:[UIFont systemFontOfSize:15]];  

good luck


Objective-C:

[button.titleLabel setFont: [button.titleLabel.font fontWithSize: sizeYouWant]];

Swift:

button.titleLabel?.font = button.titleLabel?.font.fontWithSize(sizeYouWant)

will do nothing more than changing the font size.


button.titleLabel.font = [UIFont systemFontOfSize:size];

should help


Check on custom font name whether checkbox on "Target membership" is added. This should help.


To support the Accessibility feature in UIButton

extension UILabel
{
   func scaledFont(for font: UIFont) -> UIFont {
        if #available(iOS 11.0, *) {
            return UIFontMetrics.default.scaledFont(for: font)
        } else {
            return font.withSize(scaler * font.pointSize)
        }
    }
    func customFontScaleFactor(font : UIFont) {
        translatesAutoresizingMaskIntoConstraints = false

         self.adjustsFontForContentSizeCategory = true
         self.font = FontMetrics.scaledFont(for: font)
    }
}

You can can button font now.

UIButton().titleLabel?.customFontScaleFactor(font: UIFont.systemFont(ofSize: 12))

button.titleLabel.font = <whatever font you want>

For the people wondering why their text isn't showing up, if you do

button.titleLabel.text = @"something";

It won't show up, you need to do:

[button setTitle:@"My title" forState:UIControlStateNormal]; //or whatever you want the control state to be

Examples related to objective-c

Adding a UISegmentedControl to UITableView Keep placeholder text in UITextField on input in IOS Accessing AppDelegate from framework? Warp \ bend effect on a UIView? Use NSInteger as array index Detect if the device is iPhone X Linker Command failed with exit code 1 (use -v to see invocation), Xcode 8, Swift 3 ITSAppUsesNonExemptEncryption export compliance while internal testing? How to enable back/left swipe gesture in UINavigationController after setting leftBarButtonItem? Change status bar text color to light in iOS 9 with Objective-C

Examples related to cocoa-touch

Include of non-modular header inside framework module Move textfield when keyboard appears swift Create space at the beginning of a UITextField Navigation bar with UIImage for title Generate a UUID on iOS from Swift How do I write a custom init for a UIView subclass in Swift? creating custom tableview cells in swift How would I create a UIAlertView in Swift? Get current NSDate in timestamp format How do you add an in-app purchase to an iOS application?

Examples related to ios

Adding a UISegmentedControl to UITableView Crop image to specified size and picture location Undefined Symbols error when integrating Apptentive iOS SDK via Cocoapods Keep placeholder text in UITextField on input in IOS Accessing AppDelegate from framework? Autoresize View When SubViews are Added Warp \ bend effect on a UIView? Speech input for visually impaired users without the need to tap the screen make UITableViewCell selectable only while editing Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture arm64

Examples related to uibutton

How to make a simple rounded button in Storyboard? How to set the title text color of UIButton? How can I make a button have a rounded border in Swift? How to change UIButton image in Swift Changing text of UIButton programmatically swift Disable a Button How to change font of UIButton with Swift Attach parameter to button.addTarget action in Swift Change button background color using swift language Make a UIButton programmatically in Swift

Examples related to font-size

Specifying Font and Size in HTML table How can I set the font-family & font-size inside of a div? How to change Bootstrap's global default font size? How to set min-font-size in CSS Is there such a thing as min-font-size and max-font-size? How can I change the font-size of a select option? Font scaling based on width of container Auto-fit TextView for Android Responsive font size in CSS increase font size of hyperlink text html