0

I creat a button set the background image.then add a label to the button,I try to modify the size of font in label but failed.I don't know how to solve this ,anyone help me please.

this is my code:

returnButton = [UIButton buttonWithType:UIButtonTypeCustom];
    returnButton.frame = CGRectMake(10, 9, 50, 28);

    [returnButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [returnButton setImage:[UIImage imageNamed:@"US MEAT_buttons.png"] forState:UIControlStateNormal];
    [returnButton setImage:[UIImage imageNamed:@""] forState:UIControlStateHighlighted];

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(8, 2, 50, 20)];
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont fontWithName:@"STHeiti-Medium.ttc" size:10];
    label.text = @"返回";//返回means "return"
    [returnButton addSubview:label];
    [label release];
Beraliv
  • 518
  • 7
  • 20
Amour Ring
  • 141
  • 7

2 Answers2

1

Perhaps your custom font has not been added properly:

  1. Add the font files to your resource files
  2. Edit your Info.plist: Add a new entry with the key Fonts provided by application.
  3. For each of your files, add the file name to this array

    label.font = [UIFont fontWithName:@"STHeiti-Medium" size:10];

Please check the following answer How to include and use new fonts in iPhone SDK?

Community
  • 1
  • 1
Hiren
  • 12,720
  • 7
  • 52
  • 72
0

If you want to add custom fonts, that has to be in resources folder, and you need to add that font details into plist file. Check this answer

Community
  • 1
  • 1
arthankamal
  • 6,341
  • 4
  • 36
  • 51