FontAwesome for UITTabBarController - ios

I am working on building a mobile app to compliment a website and I need to mimic the icons used on the site. The icons are from FontAwesome and I want them to appear as my UITabBar Items. I have successfully installed the FontAwesome into my project and then I was able to add the icon into a label, but I can't figure out how to get the icon to render in my tab bar item.
The code I used to render the icon in the label:
self.label.font = [UIFont fontWithName:#"FontAwesome" size:12];
self.label.text = [NSString stringWithFormat:#"%#", #"\uf007"];
I have also tried typing in "\uf007" into the title of the icon, and then changing the font in my viewDidLoad method, but that did not work. Thank you for any help!
EDIT
My reputation is below 10 so the link to the image is: uitabbaritem
In the image above, I am manually typing in the code I want to show. If I change the font to FontAwesome, the text stays the same.

[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor blackColor], UITextAttributeTextColor,
[UIFont fontWithName:#"font" size:0.0], UITextAttributeFont,
nil]
forState:UIControlStateHighlighted];
Reference - iOS5 TabBar Fonts and Color

Related

How to set navigationbar font and colors

I am trying to set the color of my navigation bar. I have added my font in the plist file and added it as a resource, and I can select it as font in the storyboard when using a UILabel. So the font seems to be there.
I have tried this in the app delegate:
NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:myLightBrownColor, NSForegroundColorAttributeName,[UIFont fontWithName:#"Pacifico" size:17.0f], NSFontAttributeName,
myShadow, NSShadowAttributeName, nil];
[navigationBarAppearance setTitleTextAttributes:textTitleOptions];
And this in the view controller directly:
NSShadow *myShadow = [MRStyleController getMyShadow];
NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[MRStyleController getLightBrownColor], NSForegroundColorAttributeName,[UIFont fontWithName:#"Pacifico" size:17.0f], NSFontAttributeName,
myShadow, NSShadowAttributeName, nil];
self.navigationController.navigationBar.titleTextAttributes = textTitleOptions;
However, none of this did change the apps navigation bar title font and color.
Any suggestions?
EDIT:
what correctly works is:
UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
[navigationBarAppearance setBarTintColor:myBrownColor];
NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:myLightBrownColor, NSForegroundColorAttributeName,
myShadow, NSShadowAttributeName,
[UIFont fontWithName:#"AmericanTypewriter" size:16.0], NSFontAttributeName, nil];
[navigationBarAppearance setTitleTextAttributes:textTitleOptions];
This will change the font to "American TypeWriter".
But I have a custom font named "Pacifico", which is in my "Supporting Files" folder, as "Pacifico.ttf", and listed in my info.plist as "Fonts provided by application", but the font isn't changing, so somehow the custom font is not correctly referenced?
For navigation bar title use
self.navigationController.navigationBar.titleTextAttributes= #{
NSForegroundColorAttributeName: [UIColor purpleColor],
NSFontAttributeName: [UIFont robotoMediumFontSize : 20.0],
};
self.navigationItem.title=#"MY Title";
For setting navigation bar background color use
self.navigationController.navigationBar.barTintColor=[UIColor myColor];
I found the solution, the font needs to be added in the info.plist as described above, but additionally in ---> Build Phases ---> Copy Bundle Resources added.

UISegmentedControl always appears dim

No matter what settings I try, I cannot get UISegmentedControl to render with the tintColor I set. I took a few screenshots, and it seems whatever color I set, the rendered result is 20% darker (i.e. UIColor whiteColor ends up R:204,G:204,B:204)
I've tried every combination of the settings below, and nothing seems to change the fact it always looks darker. However, inspection of the tintAdjustmentMode at all stages before/after setting the values, appear, etc. comes out as UITintAdjustmentModeNormal. I can make the background color of the text render at full brightness, but the frame and selected index fill is always at 80% brightness. Oddly, this doesn't happen in the 7.1 Simulator, but it does happen on my iPhone 5 with 7.1.1.
Has anyone had similar problems? I've read many other threads about controls not dimming, or people wanting to set different colors for different parts of the control, but couldn't find any about tintColors that won't show at full brightness.
Various settings I've tried individually and together:
UIColor *tintColorToSet = [UIColor colorWithRed:0/255.0f green:241/255.0f blue:1.0f alpha:1.0f];
NSMutableDictionary *textAttributes = [NSMutableDictionary dictionaryWithObjectsAndKeys:
tintColorToSet, NSForegroundColorAttributeName,
[UIColor clearColor], NSBackgroundColorAttributeName,
[UIFont fontWithName:#"NesController" size:18.0f], NSFontAttributeName, nil];
[_lengthBar setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
[textAttributes setValue:[UIColor blackColor] forKey:NSForegroundColorAttributeName];
[_lengthBar setTitleTextAttributes:textAttributes forState:UIControlStateSelected];
_lengthBar.tintColor = tintColorToSet;
_lengthBar.alpha = 1.0f;
_lengthBar.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
Thanks for the help.

Possible to detect Bold Text setting in Settings > Accessibility?

With iOS 7, it's possible to code your app to respect the user's setting for Dynamic Type - larger or smaller font sizes. You use the method preferredFontForTextStyle: and then listen to notifications in order to update the UI if the user changes the setting while your app is running. I am wondering if it's possible to do the same thing with the accessibility option "Bold Text" found in Settings > Accessibility. I realized that the Bold Text option actually requires you to restart the device, so there should be no need to listen to notifications because your app will be killed and relaunched anyways.
This is what I ultimately want to accomplish: I would like to change the navigation bar title text to a lighter style font. It may not be the default System font - it could be any font iOS can display, but I'll probably use HelveticaNeue-Light. I would also like to respect the user's preference for Bold Text. If it's enabled, I want to change the title text to a heavier weight of that same font - just like iOS does by default even though the default is already quite heavy - Helvetica Neue Medium. Indeed it does make it a little bit heavier when enabled. I want to do the same with a different font.
Here's what I'm doing to change it, but this obviously will be fixed no matter what the bold setting is:
[self.navigationController.navigationBar setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:#"HelveticaNeue-Light" size:17], [NSFontAttributeName, nil]];
I may have a solution but it seems to be a bad approach. I'm making a new font with a fixed size from the preferredFont for subheadline. This does almost exactly what I want - it automatically takes care of font-weight based on the Bold Text setting (HelveticaNeueRegular [I actually want Light] when disabled, HelveticaNeueMedium when enabled), but won't work for a different typeface. Perhaps there is a better approach?
UIFont *subtitleFont = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
UIFont *titleFont = [subtitleFont fontWithSize:17];
[self.navigationController.navigationBar setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:titleFont, NSFontAttributeName, nil]];
As of iOS 8, it is possible to detect whether the user has enabled Bold Text in Settings using UIAccessibility.isBoldTextEnabled (docs) and UIAccessibility.boldTextStatusDidChangeNotification (docs).
For apps that also require iOS 7 support, I’ve written an elegant one-liner that works on iOS 7 & 8 with Helvetica Neue and even on iOS 9 with the San Francisco typeface, based on the fact that standard-weight fonts are commonly referred to as the “Regular” weight, and that body text uses this weight for readability:
Objective-C:
BOOL hasBoldText = ![[UIFont preferredFontForTextStyle:UIFontTextStyleBody].fontName hasSuffix:#"-Regular"];
Swift:
let hasBoldText = !UIFont.preferredFontForTextStyle(UIFontTextStyleBody).fontName.hasSuffix("-Regular")
You can use UIFontDescriptor for that:
UIFontDescriptor *fontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleSubheadline];
UIFont *font = [UIFont fontWithDescriptor:fontDescriptor size:17]; // better to use a constant
If you want to change when the font size changes, you can observe the UIApplicationContentSizeDidChangeNotification. I'm not sure if the Bold Text setting also sends this notification, but you can always update on applicationWillEnterForeground:. 99% of the time you update unnecessarily that way, but it should work if the user does decide to change it.
I found another solution. Just parse the current title font to see if it contains the substring 'bold' and if it does not find it, then you know Bold Text is disabled, and you can apply your custom font. Note that this would stop working if Apple changed the heading weight. For example, took it down one notch to Regular and Medium instead of Medium and Bold. And if Apple changes the font family, your fixed font won't match it obviously. But it doesn't seem to be a terrible solution.
UIFont *currentTitleFont = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
//if Bold Text is disabled
if ([currentTitleFont.fontName rangeOfString:#"bold" options:NSCaseInsensitiveSearch].location == NSNotFound) {
UIFont *titleFont = [UIFont fontWithName:#"HelveticaNeue-Light" size:17];
[self.navigationController.navigationBar setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:titleFont, NSFontAttributeName, nil]];
}
else {
//put custom font here for when Bold Text is enabled, or do nothing to get the default
}
In iOS 7 and up, I noticed that the UIFontTextStyleHeadline is: HelveticaNeueInterface-Heavy.
I modified the op's response as follows:
UIFont *currentTitleFont = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
//if Bold Text is disabled
if ([currentTitleFont.fontName rangeOfString:#"bold" options:NSCaseInsensitiveSearch].location == NSNotFound && [currentTitleFont.fontName rangeOfString:#"heavy" options:NSCaseInsensitiveSearch].location == NSNotFound) {
UIFont *titleFont = [UIFont fontWithName:#"HelveticaNeue-Light" size:17];
[self.navigationController.navigationBar setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:titleFont, NSFontAttributeName, nil]];
}
else {
//put custom font here for when Bold Text is enabled, or do nothing to get the default
}
Try this one. It works for me.
let hasBoldText = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.body).fontName.contains("bold")
UIFont.preferredFont(forTextStyle: UIFont.TextStyle.body).fontName
11.4 12.0
".SFUIText"
".SFUIText-Semibold"
13.3

".SFUI-Regular"

".SFUI-Semibold"

Setting a custom font for UIBarButton works in one version but not another

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).

In iOS7, UIBarButtonItems do not respect bold "Done" styling when using UIAppearance proxy

In iOS7, by default UIBarButtonItem uses a Helvetica regular weight font for style UIBarButtonItemStylePlain and a bold weight for UIBarButtonItemStyleDone.
My app uses custom fonts, and I'm using a UIAppearance proxy to achieve this:
appearance = #{NSFontAttributeName: [UIFont fontWithName:#"ProximaNova-Regular" size:18.0]};
[[UIBarButtonItem appearance] setTitleTextAttributes:appearance
forState:UIControlStateNormal];
The trouble is, the appearance proxy makes the Plain and Done styled buttons the regular weight font I specified above.
Any ideas how I could get UIBarButtonItem to use different custom font weights depending on the style?
I know it is late answer, but it can be helpful for somebody:
UIBarButtonItem *customBarButton =
[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"CustomTitle", #"This button appears in my smexy ViewController's naviagtion bar")
style:UIBarButtonItemStylePlain
target:self
action:#selector(customButtonDidClick:)];
NSDictionary *attributes = #{NSFontAttributeName: [UIFont fontWithName:#"TimesNewRomanPS-BoldMT" size:14.0f],
NSForegroundColorAttributeName: [UIColor redColor]}; // here you can add some other keys (especially in iOS 7) to personalize your button title more
[customBarButton setTitleTextAttributes:attributes forState:UIControlStateNormal];
[self.navigationItem setRightBarButtonItem:customBarButton];
Edited: thanks for detection of my typo :-)

Resources