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.
Related
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 UITextField that is loaded from a xib. In it's view controllers viewDidLoad method, I set the font to a custom value which is set up correct in the .plist file and everything. It displays fine except for when it is in edit mode, at which point the font switches from my custom font to the default font, which I believe is Helvetica. This is jarring, and I'd like to keep the custom font throughout. I've looked around and I don't see any immediate solution, the only thing I've tried is resetting the textField.font property in the textFieldShouldBeginEditing and textFieldDidBeginEditing delegate methods, neither of which did anything.
Edit: I've been asked for the code, it really only is one line but here goes.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.myTextField.font = [UIFont fontWithName:#"MyFont" size:18];
}
I've also tried resetting the font in the following two methods:
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
textField.font = [UIFont fontWithName:#"MyFont" size:18];
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
textField.font = [UIFont fontWithName:#"MyFont" size:18];
return YES;
}
This does nothing, the font still changes while editing takes place, but then changes back to the custom font once the keyboard is dismissed.
Second edit:
Well, I just did something I probably should have tried before, and used a couple of different font files. Both of those fonts worked fine, but for whatever reason the custom font file I was using is causing the problem, despite it working normally in all other situations.
I had this problem with an otf font (in fact I've always had problems with otf fonts...) so now I use only ttf fonts, which work great. Check out this font converter website if you need to convert fonts from otf.
Try this:
- (void)textFieldDidChange:(UITextField *)textField {
textField.font = [UIFont fontWithName:#"MyFont" size:18];
}
Or as an alternative to fhat create an IBAction, connect it to the textField with Editing Changed and add this code to your .m:
- (IBAction)textFieldEditingChanged:(id)sender {
textField.font = [UIFont fontWithName:#"MyFont" size:18];
}
From my experience, the problem is with the font file. I found that the only solution was to find an alternative font and switch.
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.
I'd like to use a UIWebView with the same typographical appearance as the rest of my app texts which all use [UIFont systemFontOfSize:15]. But before doing some forensic research maybe someone knows what font that really is?
You should be able to inspect the fontName property of the UIFont returned by [UIFont systemFontOfSize:15].
NSString *fontName = [UIFont systemFontOfSize:15].fontName;
Mostly HelveticaNeueInterface-Regular (iOS7+)
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];