Question

I have a subclass of UIButton that uses a custom font. The problem is that capital letters don't show diaeresis.

Below there are images of the same button sample with and without the custom font. I set the title's background color to red to see what is going on.

Without custom font

without custom font

With custom font

with custom font

My UIButton subclass overrides awakeFromNib

- (void)awakeFromNib
{
    [super awakeFromNib];
    UIFont *font = [UIFont fontWithName:@"TitilliumText22L-Bold" size:self.titleLabel.font.pointSize];
    self.titleLabel.font = font;
}

Can anyone tell me what to do in order to show the diaeresis on top of capital letters?

Thanks.

Was it helpful?

Solution

I solved this problem by following this answer on the question shared by Bob https://stackoverflow.com/a/8314197/617787

The only thing to be aware of this solution (changing the "ascender" of the font file) is that the space between lines on multiline UILabels using this modified font will change as well, so you might use NSAttributedString to modify it in a per case basis.

OTHER TIPS

Easy and best solution.

  1. Select the button in the interface
  2. In the attribute inspector, change the vertical alignment as shown in the image.

I ve made some tests about this with Turkish characters, see the result:

3 Buttons and 1 UILabel with NeoSansPro font and capital TR chars

  1. UILabels show the capital letters correctly.
  2. UIButton with helvetica font shows the characters correctly (third button) but the problem occurs with all members of NeoSansPro family.
  3. The problem only occurs on the top line of the title label (button 2)

The solution:

Practically a hack, use at your own risk. I'd rather recommend follwign Javier's answer above

  1. Set the title label's number of lines: 0
  2. Set title "\nBUTTON TITLE" instead of "BUTTON TITLE"
  3. In the IB or code, play with the content and title alignment, until the title is displayed correctly. You should push the title a little upwards if you want it in the middle

seems like that the text in getting cut, try to reduce the font size or change the frame of the titleLable (property of UIButton)

I had a similar problem, where a diaeresis got cut off on top of the titlelabel. I made a UIButton subclass and used this code to fix the problem:

-(void)layoutSubviews
{
    [super layoutSubviews];

    CGRect frame = self.titleLabel.frame;
    frame.size.height = self.bounds.size.height;
    frame.origin.y = self.titleEdgeInsets.top;
    self.titleLabel.frame = frame;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top