Here is the code we finally used. Help from John Wang.
Thanks everyone for the suggestions!
// Formats a label to add to a button. Supports multiline buttons // Parameters: // button - the button to add the label to // height - height of the label. usual value is 44 // offset - the offset from the top of the button // labelText - the text for the label // color - color of the text // formatAsBold - YES = bold NO = normal weight // tagNumber - tag for the label - (void) formatLabelForButton: (UIButton *) button withHeight: (double) height andVerticalOffset: (double) offset andText: (NSString *) labelText withFontSize: (double) fontSize withFontColor: (UIColor *) color andBoldFont:(BOOL) formatAsBold withTag: (NSInteger) tagNumber { // Get width of button double buttonWidth= button.frame.size.width; // Initialize buttonLabel UILabel *buttonLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, offset, buttonWidth, height)]; // Set font size and weight of label if (formatAsBold) { buttonLabel.font = [UIFont boldSystemFontOfSize:fontSize]; } else { buttonLabel.font = [UIFont systemFontOfSize:fontSize]; } // set font color of label buttonLabel.textColor = color; // Set background color, text, tag, and font buttonLabel.backgroundColor = [UIColor clearColor]; buttonLabel.text = labelText; buttonLabel.tag = tagNumber; // Center label buttonLabel.textAlignment = UITextAlignmentCenter; // Add label to button [button addSubview:buttonLabel]; [buttonLabel autorelease]; } // End formatLabelForButton
source share