0

Recently I was looking to use the custom font SS-Standard in a iOS application. After finding that the PostScript name is SSStandard, adding the font ttf file to the project and adding to the .plist, I can change a UILabel by calling:

[myLabel setFont:[UIFont fontWithName:@"SSStandard" size:fontSize]];

This however only works in iOS7, and to make it work in iOS6 (and possibly below, I haven't tested though) I have to replace the above with:

NSMutableAttributedString *attributedString =
  [[NSMutableAttributedString alloc] initWithString:myString
  attributes:@{
    NSFontAttributeName: [UIFont fontWithName:@"SSStandard" size:iconFontSize],
    NSLigatureAttributeName: @2
  }];
myLabel.attributedText = attributedString;

Now this all works fine, however I'm also trying to set a custom font within a UIBarButton. I can do this for iOS7:

NSDictionary *barButtonAppearanceDict = @{
    NSFontAttributeName : [UIFont fontWithName:SYMBOL_SET_NAME size:15],
    NSLigatureAttributeName : @2
};
[button setTitleTextAttributes:barButtonAppearanceDict forState:UIControlStateNormal];

But for iOS6 it doesn't load the new font. I was wondering if anyone has ever come across this (with any custom font).

ingh.am
  • 25,981
  • 43
  • 130
  • 177
  • @Mr CoDeXeR The issue I'm having is specific to this OS version. How is that not appropriate to put in the title? – ingh.am Feb 20 '14 at 15:58
  • Because you already have a tag related to the version, that's why. – Trevor Feb 20 '14 at 16:00
  • I'm not forcing the tag into the title http://stackoverflow.com/help/tagging – ingh.am Feb 20 '14 at 16:04
  • Avoid meta-tags Do not use meta-tags in questions. Here are some tips to help you determine whether a tag is a meta-tag: http://stackoverflow.com/help/tagging – Trevor Feb 20 '14 at 16:08
  • @MrCoDeXeR Here's a few (out of hundreds) more posts for you to moderate: http://stackoverflow.com/questions/18972938/custom-inputview-for-uisearchbar-doesnt-work-in-ios7?rq=1 http://stackoverflow.com/questions/19008155/uitextfield-within-uisearchbar-in-ios-7?rq=1 http://stackoverflow.com/questions/18993773/uitextfield-not-working-as-subview-to-uisearchbar-in-ios-7?rq=1 http://stackoverflow.com/questions/18967364/uisearchbar-customization-code-crashes-in-ios7-works-on-ios6?rq=1 http://stackoverflow.com/questions/19756284/different-vertical-alignment-font-between-ios6-and-ios7?rq=1 – ingh.am Feb 20 '14 at 16:13
  • Thank you, I'll be sure to check them out. – Trevor Feb 20 '14 at 16:13
  • Also the suggested edit required peer review, if they didn't agree with me then the title wouldn't have been changed. Therefore it was agreed by another use. – Trevor Feb 20 '14 at 16:15
  • 1
    Here's 2,907 more for you to go through http://stackoverflow.com/search?q=%22ios7%22+%5Bios7%5D – ingh.am Feb 20 '14 at 16:17
  • Thank you for the suggested input. – Trevor Feb 20 '14 at 16:19
  • 1
    Here is 85,000+ in .NET for you to go through too http://stackoverflow.com/search?q=%22.net%22+%5B.net%5D – ingh.am Feb 20 '14 at 16:19
  • Just taking a chance.. Is the font chosen available in iOS6? – Akshat Singhal Feb 20 '14 at 16:23
  • I'll try printing out a list and see, however as described in the post I can use the font on UILabels. – ingh.am Feb 20 '14 at 16:23
  • That's more constructive now, thank you. – Trevor Feb 20 '14 at 16:23
  • @AkshatSinghal Calling `NSLog (@"Font families: %@", [UIFont familyNames]);` does indeed print out the font name I'm trying to use. – ingh.am Feb 20 '14 at 16:26
  • Did you try to use `[buttonItem setTitleTextAttributes:@{ UITextAttributeFont:, UITextAttributeTextColor: } forState:UIControlStateNormal];`? – Akshat Singhal Feb 20 '14 at 16:29
  • Yea. Someone had posted that as an answer (then closed it) but it doesn't work for iOS6. – ingh.am Feb 20 '14 at 16:31
  • And even `button.titleLabel.font=` did not work? – Akshat Singhal Feb 20 '14 at 16:32
  • There isn't a `button.titleLabel`, you can only set `title` which is of type `NSString *`. – ingh.am Feb 20 '14 at 16:34
  • Correct me if I am going wrong but to the best of my knowledge, UIBarButton is a subClass of UIButton, and UIButton has the method setTitleLabel.. – Akshat Singhal Feb 20 '14 at 16:35
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/47975/discussion-between-akshat-singhal-and-ing0) – Akshat Singhal Feb 20 '14 at 16:54

0 Answers0