I have a UIButton which displays a text, with the following code:
[button setTitle:#"Join this group" forState:UIControlStateNormal];
however, how do I change the font size for this?
I tried
button.titleLabel.font = [UIFont fontWithName:#"Arial-MT" size:8.0];
but I think it's a totally different thing.
Or at least how do I make the text to adjust to the size of the button frame.
Should I just use textLabel.text instead?
The reason that the code you're posting isn't working is probably because Arial isn't present in iOS. You can change the properties of a UIButton's titleLabel just like any other instance of UILabel. Read about that here.
So, you can change the font size with something like:
button.titleLabel.font = [UIFont systemFontOfSize:14.0];
You can choose a font by name, but not all fonts are available on iOS. Here's a list of ones that are.
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 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.
I have a simple UILabel setup and was receiving reports from some users that they could not see the information. I did some testing and found that I can see the text on my iPhone 4, but when I test on my old iPhone 3G, the text of the label does not appear. I can see the label (it has a colored background) but there is no text.
I am assuming most of the users have a 3GS or better, but have not nailed it down to exactly who is / is not seeing the error.
Any ideas why this could be happening ?
myLabel is linked up to a UILabel in interface builder.
myLabel.backgroundColor = [UIColor redColor];
myLabel.textColor = [UIColor blueColor];
myLabel.text = #"MY MESSAGE";
myLabel.frame = CGRectMake(0, 100, 320, 40);
I had this problem and tracked it down to a font problem. Helvetica Neue Medium does not appear on my iDevices running iOS 4.2.1. Helvetica Neue Regular is visible on them.
Im assuming that you are using a standard UILabel and not some subclass found on the internet. Are you using a custom font? Are you seeing the red backround? There are many things that could be going wrong, we need some more information.
I have a problem: I want to change the font in my UILabel. When I select the text in the UILabel and I change the font it works, but when I unselect the text, the font comes back to defaut.
Someone have an idea?
Thx
Are you doing it in interface builder? It is very straight forward though. You can also do that using code.
lblName.font= [UIFont fontWithName:#"Arial" size:15];
Something like this.
UIFont *myFont = [ UIFont fontWithName: #"Arial" size: 18.0 ];
textLabel.font = myFont;
This should change the font, however Are you changing it in IB? Also it depends on the type of font you are selecting. It may not be visible in IB and rendering on device depends on the fonts available on it.
labelName.font=[UIFont boldSystemFontOfSize:18]; or any other font style can be assigned as desired.
I made an totally custom navigation bar and would like to use the exact same font and size like apple does for the title of their navigation bar. It looks like some kind of fat printed arial, but not sure if that's right. Does anyone know?
iOS12 - iOS15 Large Title - System Bold 34 (San Francisco)
[UIFont boldSystemFontOfSize:34]
iOS9 - iOS15 Regular centered title - System Semibold 17 (San Francisco)
[UIFont systemFontOfSize:17 weight:UIFontWeightSemibold]
iOS8 - System Semibold 17 (Helvetica Neue)
[UIFont systemFontOfSize:17 weight:UIFontWeightSemibold]
iOS7 - System Bold 17 (Helvetica Neue)
[UIFont boldSystemFontOfSize:17];
Nice link about typo in iOS
https://learnui.design/blog/ios-font-size-guidelines.html
Definitely not Arial. It's Helvetica. You can probably get the same font using
UIFont *navFont = [UIFont boldSystemFontOfSize:18];
Change the size to find out what Apple is using (and write it below in a comment if you find the best one).
All the navigation bar text has a white shadow underneath it to give it the embossed effect. It's a white shadow 1 pixel underneath the text. Use shadowColor and shadowOffset in a UILabel to get the same effect.
For iOS7 the correct font size is 17pt:
UIFont *navFont = [UIFont boldSystemFontOfSize:17];
UIFont *navFont = [UIFont boldSystemFontOfSize:22];