1

I try change the size and font of button, but the changes don't work!

I try using Interface Build, and after delete and test again with this code:

[botaoCadastrar.titleLabel setFont:[UIFont fontWithName:@"MyriadPro" size:18]];

But don't work!

I followed this tutorial:

The solution for that is to add your fonts to your app, so you will have a unique app design. To do so, simply follow these steps:

1 - Add your font files to your project in XCode (The files should appear as well in “Target -> Build Phases -> Copy Bundle Resources”).

2 - In your “Info.plist” file, add the key “Fonts provided by application” with type “Array”.

3 - For each font you want to add to your project, create an item for the array you have created with the full name of the file including its extension (e.g. myfont.ttf).

4 - Save your “Info.plist” file.

  • 3
    MyriadPro isn't a standard iOS font, did you add the font to your project? http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/ – Guillaume Algis Nov 13 '14 at 13:23
  • possible duplicate of [Set UIButton title label font size programmatically](http://stackoverflow.com/questions/1465305/set-uibutton-title-label-font-size-programmatically) – gran33 Nov 13 '14 at 13:24
  • Yes i try insert this font in my project, I will complement the question. –  Nov 13 '14 at 13:27

4 Answers4

3

Set the font of the button's.

myButton.titleLabel.font = [UIFont fontWithName:@"Courier" size:14.0];

If you want a custom font, please refer this link.

http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/

Kanhaiya
  • 249
  • 1
  • 2
  • 8
0
[myButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:13.0]];

this is working if not check font name or button outlet is properly attached

Waseem Shah
  • 2,219
  • 23
  • 23
  • I will complement the question because it comes from a source that does not have the Xcode. I am trying to insert this source into the project. –  Nov 13 '14 at 13:26
  • then you check your font first apply this font on simple UIlabel if there this font working then you check UIbutton outlet – Waseem Shah Nov 13 '14 at 13:34
0

You need to add MyriadPro font to your project and to info.plist file for key UIAppFonts (Fonts provided by application). Then you can use your code to set font,

[botaoCadastrar.titleLabel setFont:[UIFont fontWithName:@"MyriadPro" size:18]];

Reason:

The MyriadPro font is not iOS default font. You can find default font list here,

  1. iOS 6 - http://support.apple.com/en-us/ht5484
  2. iOS 7 - http://support.apple.com/en-us/ht5878
  • I insert the font name wrong, thx!! The correctly is @"Myriad Pron"; I don't inset whitespace between the names.! –  Nov 13 '14 at 13:43
-1
UIButton *botaoCadastrar = [UIButton buttonWithType:UIButtonTypeCustom];
[botaoCadastrar setAttributedTitle:@{NSFontAttributeName:[UIFont fontWithName:@"MyriadPro" size:18]} forState:UIControlStateHighlighted];
[botaoCadastrar setAttributedTitle:@{NSFontAttributeName:[UIFont fontWithName:@"MyriadPro" size:10]} forState:UIControlStateNormal];
Bimawa
  • 3,535
  • 2
  • 25
  • 45