ICL1901
ICL1901

Reputation: 7778

Localizing a custom UIButton in xCode

I am stumped trying to add a localized label to a custom button.

I have tried this:

[button1 setImage:[UIImage imageNamed:buttonFile] forState: UIControlStateNormal];
    NSString *buttonTitle =  NSLocalizedString(@"RECORD", @"");
    [button1 setTitle:buttonTitle forState:UIControlStateNormal];

this:

for (id label in [button1 subviews])                
  if ([label isKindOfClass:[UILabel class]])
  {
    [label setTextAlignment:UITextAlignmentCenter];
    [label setFont:[UIFont fontWithName:fontName size:14]];
    [label setText: NSLocalizedString(@"RECORD", @"")];// forState:UIControlStateNormal];
  }

and this:

button1.titleLabel.text = NSLocalizedString(@"RECORD", @"");

I can see the button, but not the label. If I remove the button image, I can see the label. I'd really like to have both, and I'd prefer not to have buttons for each language, although that is possible..

Are there better ways?

Thanks!!

Upvotes: 0

Views: 1006

Answers (1)

fbernardo
fbernardo

Reputation: 10124

Use setBackgroundImage:ForState: instead of setImage:

Upvotes: 1

Related Questions