My custom TrueType font file that I brought into Xcode is not displaying correctly in the UINavigationBar. Instead of displaying the custom font, it displays the System font (Helvetica Bold).
RootViewController.m
self.title = #"Library";
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIFont fontWithName:#"adellebasic_bold.ttf" size:20.0], UITextAttributeFont,nil]];
I have also made sure that I copied it into Xcode correctly and I declared it under UIAppFonts in the Info.plist file. Also note that the code works if I set it to a UIFont that is included in the iPhone SDK but not a custom font brought in.
Does anyone have the slightest idea for what I'm doing wrong here?
Try this:
NSMutableDictionary *titleBarAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] titleTextAttributes]];
[titleBarAttributes setValue:[UIFont fontWithName:#"adellebasic_bold" size:25.0f] forKey:UITextAttributeFont];
[self.navigationController.navigationBar setTitleTextAttributes:titleBarAttributes];
[self.navigationController.navigationBar setTitleVerticalPositionAdjustment:4.0f forBarMetrics:UIBarMetricsDefault];
Hope this helps.
actually the font file name and the font name are two different things.
Check This: iOS: How can i set a non system font family, style, size of UILabel? .
Try this name "Adelle Basic Bold".
Related
I have added button in interface builder and referenced them, then I want to change their title font, but it doest work.
When I use:
[_button setFont:[UIFont fontWithName:APP_FONT_FUTURASTD_LIGHT size:24.0f]];
it WORKS, but this code is depreciated. So I have looked online to see what to use instead of this code, I found this code to use:
[_button.titleLabel setFont:[UIFont fontWithName:APP_FONT_FUTURASTD_LIGHT size:24.0f]];
_button.titleLabel.font = [UIFont fontWithName:APP_FONT_FUTURASTD_LIGHT size:24.0f];
but NEITHER of this work. I have no idea what to do with it or what is wrong. I have tried to set globally appearance of UIButton, that works too, but I cant use it as I need that font only on some buttons.
Button is as:
#property (nonatomic, weak) IBOutlet UIButton *button;
and added in storyboard.
Font is defined:
#define APP_FONT_FUTURASTD_LIGHT #"FuturaStd-Light"
and added to Info.plist section "Fonts provided by application".
I have found out what the problem was. The other programmer who has started this project has set
[[UIButton appearance] setFont:[UIFont fontWithName:APP_FONT_FUTURASTD_BOLD size:12.0f]];
in CSAppDelegate.m and so all my customizations were overwritten by this.
So to anyone who configures buttons font globally like this, you will not be able to then customize font of some buttons differently.
And second advice, if you continue work after someone else make sure that they give you some technical documentation or to explain to you what how and where they did.
EDIT
You can however set appearance for one view in viewWillAppear and then set it back to what you have in your CSAppDelegate.m in viewDidAppear of the view.
EDIT
Now this code is depreciated so you have to use this instead:
[[[UIButton appearance] titleLabel] setFont:UIFont];
The Problem seems to me is the Font name. The Font Name you are using in the code is not the exact name.
You Can Use the Following code to get List Of all Fonts name supported by your app
// List all fonts on iPhone
for (NSString* family in [UIFont familyNames])
{
NSLog(#"%#", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(#" %#", name);
}
}
from the Console of xcode you can find out the exact name of the font that you added in your application
Please remove the AutoLayout checkmark if You used with Xib.It will works fine.
I think its helps to you.
I am creating TextEditor application in iphone sdk. In my app I like to change the color and font when ever the user needs while editing the text. For creating this I have refer some of the following library
Ego TextView-It allowed to change different font but setcolor property is not available
RichTextKit - SetKeyboard, setAutoCorrent is not available
But non of them is worked for me. Can any one suggest some idea to create multiple color and multiple font TextEditor in iPhone SDK?
For multiple font and multiple color, You can go for CG or even NSAttributedString.
NSMutableAttributedString *attributedString = [NSMutableAttributedString attributedStringWithString:#"colorfull text"];
[attributedString setFont:[UIFont systemFontOfSize:15]];
[attributedString setTextColor:[UIColor redColor]];
[attributedString setTextColor:[UIColor greenColor] range:NSMakeRange(3,7)];
Our designer asked me to use specific color for text of disabled UIBarButtonItems. That code I've used to implement this:
NSDictionary* textAttributes = [NSDictionary dictionaryWithObject: [UIColor blueColor]
forKey: UITextAttributeTextColor];
[[UIBarButtonItem appearance] setTitleTextAttributes: textAttributes
forState: UIControlStateDisabled];
But it doesn't changed text attributes.
I've tried this code with Normal state, tried to chage background for UIControlStateDisabled buttons with setBackgroundImage and all thouse experiments works perfectly. But this single combination: setTitleTextAttributes and UIControlStateDisabled doesn't do anything.
Google didn't give me any relevant answer about that specific combination.
Does anybody know other way to change color of disabled UIBarButtonItem or way to make setTitleTextAttributes work for diabled items?
You have to set it for both control state Normal and Disabled.
(2015-11-18 -- As of iOS 9.1 you must still set both.)
It's working fine for me with iOS 5.1. Perhaps it was a 5.0 bug.
I want to increase the Text size of UITabBarItem in my application.It is not visible clearly with its default color and size.
I tried this code but give me error -->UITabBar for instant message does not declare method with selector 'setTitleTextAttributes'.
Does any know how to do it?
[yourTabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[NSValue valueWithUIOffset:UIOffsetMake(0,0)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"Helvetica" size:18.0], UITextAttributeFont, nil]
forState:UIControlStateNormal];
I think the default size is fully conveninet for the user. Anyway you want, maybe you should make your own <Tabbar> with UIView, UIButtons and UITabbar-style images.
setTitleTextAttributes:forState: is only available in iOS 5.0 or later. Please refer to UIBarItem Class Reference (UITabBarItem is subclass of UIBarItem). For prior versions of iOS, I think you'd better create your own customized tab bar.
And you may also want to try other methods from the answers in Changing font size of tabbaritem.
For that you should create dynamic tab bar using UITabbar class.
.Using this You can allow own size text ,image,color.
The only solution that i can think of so far is by adding images.. but i want the right solution...so i there any way to change the text/title color???
use this method, it is in ios 5.x
UIFont *Boldfont = [UIFont systemFontOfSize:13.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:Boldfont,UITextAttributeFont,[UIColor darkTextColor],UITextAttributeTextColor,nil];
[self.mSegmentControl setTitleTextAttributes:attributes
forState:UIControlStateNormal];
http://www.framewreck.net/2010/07/custom-tintcolor-for-each-segment-of.html
On this post there is the implementation of a category that does what you are looking for.
From iOS SDK, there is no method to do this directly.