i think this is really basic question but i try many way to change the font of UILabel
i try this code
lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 100)];
[lbl setText:#"Demo Text"];
[lbl setFont:[UIFont fontWithName:#"Comic-Sans-Ms" size:20]];
but it's not work can you please tell me why i am not getting "Comic Sans Ms" font in my label. with this code other font are working but i don't know what is problem with "Comic-Sans-MS"
Thanks..
Use custom fonts.
I take it this is iOS? It would then be because Comic Sans is not installed on iOS.
Related
i want to change my label's font using below code:
UILabel *lblBolge = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 38)];
lblBolge.text=#"Bölge";
lblBolge.font=[UIFont fontWithName:#"CarterOne" size:10];
but still i see system font and default size
any reason?
Carter font is not part of the iOS SDK. To add a custom font you need to get hold of the .ttf or .otf file of the font and add it to your project. Here's a tutorial on how to do that.
I am having an issue with iOS 7.
The code
[searchBar setImage:[UIImage imageNamed:#"icon_search"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
brings different icon sizes on iOS 6 and iOS 7.
The image size is 29x29 and 58x58#2x and under iOS 6 it's displayed properly, but in iOS 7 it's twice or even more times smaller.
What could be the issue? Thanks!
this seems to work for me:
UIImage* image = [UIImage imageNamed:#"icon_search"];
[[UIImageView appearanceWhenContainedIn:[UISearchBar class], nil] setBounds:CGRectMake(0, 0, image.size.width, image.size.height)];
To customize UISearchBarIconSearch you need the following code:
[yourSearchBar setImage:[UIImage imageNamed: #"yourImage.png"]
forSearchBarIcon:UISearchBarIconSearch
state:UIControlStateNormal];
To properly change the icon the resolution image must be exactly: 14x14, 28x28 for #2x and 42x42 for #3x.
I hope this helps :)
After facing some problems with UISearchBar in iOS 7, I decided to switch to UITextField due to the placeholder text alignment.
But I still managed to get it work by setting the image for UISearchBar and it's textfield.
UITextField *textfieldField = [searchBar valueForKey:#"_searchField"];
[searchBar setImage:[UIImage imageNamed:#"icon_search"]
forSearchBarIcon:UISearchBarIconSearch
state:UIControlStateNormal];
UIImage *whatSearchImage = [UIImage imageNamed:#"icon_search.png"];
UIImageView *whatSearchView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 29, 29)];
whatSearchView.image = whatSearchImage;
textfield.leftViewMode = UITextFieldViewModeAlways;
textfield.leftView = whatSearchView;
Funny thing, if you don't set the image for the UISearchBarIcon it will use the default one from Apple but make it big.
I would also like to see if someone has found a better solution for this.
I had the same problem, then I made size for search icon smaller and everything is ok now.
Play with icon size.
E.g. I changed size of retina image from 38x38 to 30x30, and now it works perfect. Probably iOS checks size and if it is not proper it uses instead of retina non-retina image
I am trying to set custom font and color (white) for font in my app's navigation bar title. Instead of white I get gray text color.
Here is the code I'm using to set custom font:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
label.textAlignment = UITextAlignmentCenter;
label.adjustsFontSizeToFitWidth = NO;
label.minimumFontSize = 10.0;
[label setFont:[UIFont fontWithName:#"HelveticaNeueLTCom-MdCn" size:24.0]];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor whiteColor]];
[label setText:#"View title"];
[self.navigationItem setTitleView:label];
Same thing happened when I tried to set custom font color in UITableView sections.
I know about some problems with Helvetica Neue in iPhone apps development but the color of this font works well in other parts of my projects.
Am I missing something here?
Have you tried other .ttf fonts just to test if they work? I wonder if there is something wrong with the font file itself. try this directory and see if it works.
The problem was that I've (deliberately) overriden default font for the whole application as described in this answer.
The solution was to remove this override (all the #import's and the remove .m file from the target, or just delete both of the class files.
I am having problems positioning my NSTextFields inside my views so I hope you guys can help me. I have this NSView *theView with [theView setFrame:NSMakeRect(10, 10, 64, 64)]; which positions the view exactly where I want it.
But now I am trying to add a NSTextField as a subView to theView but something isn't right. Now the image above is how it should be.
Here's my code and what it looks like:
primaryDigit = [[NSTextField alloc] init];
[primaryDigit setFrame:NSMakeRect(4, 6, 60, 58)];
[primaryDigit setFont:[NSFont fontWithName:#"Helvetica Neue" size:55]];
[primaryDigit setBezeled:NO];
[primaryDigit setEditable:NO];
[primaryDigit setSelectable:NO];
[primaryDigit setDrawsBackground:NO];
[primaryDigit setTextColor:[NSColor whiteColor]];
[primaryDigit setStringValue:#"2"];
[self addSubview:primaryDigit];
And when I do [primaryDigit setFrame:NSMakeRect(0, 0, 64, 64)]; the digit doesn't end up in the left lower corner but it does this:
Is there something fundamental that I don't understand about positioning these views? I'm quite the noobie but I still thought that I understand this. (Btw, the font is different in these images but that shouldn't cause a problem, I think?)
Update: as 'dasdom' asked me to, here's the text field with a background colour
Okay I found out what the problem is.
The text in NSTextFields need "space" around them. So when they have text they don't appear in the bottom left corner of the view but are position a bit away from it.
That also means that if NSTextFields don't have a frame that is large enough then the text may appear cut off.
An example here:
All the red space above the "2" has to be there otherwise the digit will move off the frame and gets cut off at the bottom.
I can't seem to modify the font size of a UILabel with the following code:
itemTitle.font = [UIFont systemFontOfSize:25];
As i increase the number 25 to something greater, it seems to only add a top margin to the label, which consequently pushes the text down so much, so that the text gets cut off at the bottom or completely overflows.
i have another UILabel elsewhere with systemFontOfSize 25, and it's much smaller than the itemTitle text. What's going on? Isn't 25 supposed to be an absolute value?
i am so confused on how to programmatically change font size of uilabels.
I have modified the UILabel by following code:
label.font=[label.font fontWithSize:25];
Try this and see whether is it working in your case or not???
Check that your labels aren't set to automatically resize. In IB, it's called "Autoshrink" and is right beside the font setting. Programmatically, it's called adjustsFontSizeToFitWidth.
[label setFont:[UIFont systemFontOfSize:9]];
this works for me.
For Swift 3.1, Swift 4 and Swift 5, if you only want change the font size for a label :
let myLabel : UILabel = ...
myLabel.font = myLabel.font.withSize(25)
**You can set font size by these properties **
timedisplayLabel= [[UILabel alloc]initWithFrame:CGRectMake(70, 194, 180, 60)];
[timedisplayLabel setTextAlignment:NSTextAlignmentLeft];
[timedisplayLabel setBackgroundColor:[UIColor clearColor]];
[timedisplayLabel setAdjustsFontSizeToFitWidth:YES];
[timedisplayLabel setTextColor:[UIColor blackColor]];
[timedisplayLabel setUserInteractionEnabled:NO];
[timedisplayLabel setFont:[UIFont fontWithName:#"digital-7" size:60]];
timedisplayLabel.layer.shadowColor =[[UIColor whiteColor ]CGColor ];
timedisplayLabel.layer.shadowOffset=(CGSizeMake(0, 0));
timedisplayLabel.layer.shadowOpacity=1;
timedisplayLabel.layer.shadowRadius=3.0;
timedisplayLabel.layer.masksToBounds=NO;
timedisplayLabel.shadowColor=[UIColor darkGrayColor];
timedisplayLabel.shadowOffset=CGSizeMake(0, 2);
This worked for me in
Swift 3
label.font = label.font.fontWithSize(40.0)
Swift 4
label.font = label.font.withSize(40.0)
very simple, yet effective method to adjust the size of label text progmatically :-
label.font=[UIFont fontWithName:#"Chalkduster" size:36];
:-)
This worked for me:
sequencerPlayLabel.font = [UIFont fontWithName:kTypeFont size:kTypeFontSize];
-rich
Answers above helped greatly.
Here is the Swift version.
#IBOutlet weak var priceLabel: UILabel!
*.... lines of code later*
self.priceLabel.font = self.priceLabel.font.fontWithSize(22)
In C# These ways you can Solve the problem, In UIkit these methods are available.
Label.Font = Label.Font.WithSize(5.0f);
Or
Label.Font = UIFont.FromName("Copperplate", 10.0f);
Or
Label.Font = UIFont.WithSize(5.0f);
Try to change your label frame size height and width so your text not cut.
[label setframe:CGRect(x,y,widht,height)];