Custom Font in iPad Doesnt work - iphone

In my Application i am using Custom font. i copied my font.ttf file in my project directory and i used following code to set custom font to a label.
[input setFont:[UIFont fontWithName: #"My Font" size: input.font.pointSize]]
The problem is it works perfect in iPhone 4.2 simulator but it in iPad 4.2 simulator it just Displays Default Font. How to resolve this?

Following code is use for the custom font.
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 240, 40)];
[label1 setFont: [UIFont fontWithName: #"Grinched" size:24]];
[label1 setText:#"Grinched Font"];
[[self view] addSubview:label1];
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 80, 240, 40)];
[label2 setFont: [UIFont fontWithName: #"Energon" size:18]];
[label2 setText:#"Energon Font"];
[[self view] addSubview:label2];
If you want shows the tutorial for that you visits the refrence link here
May this code help for development.
Happy codeing
Thanks and Regards
#samuel

If You Want To Use Custom-Font..Folow This Steps...
Add the font files to your resource files
Edit your Info.plist: Add a new entry with the key Fonts provided by application.
For each of your files, add the file name to this array
On the example below, I've added the font "DejaVu Sans Mono":
In your application you can the use
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 240, 50)];
[label1 setFont: [UIFont fontWithName: #"DejaVuSansMono-Bold" size:14.f]];
Or if you want to use it in html/css, just use font-family:DejaVu Sans Mono;
Note: this is available in iOS 3.2 and later.

Related

How can I add label in Xcode 4.5.2 the label should appear after the user click a button

I am trying to write my first IPhone app
in Xcode 4.5.2 I could not add atext to the label
I am trying to do the program in next video
http://youtu.be/0uVxxdZ5umY
it always not work and the error is use of undeclared identifier 'label'
and this always appear after I write labe.text
in the .m file
thank you in advance
Set an IBAction of your button. In the method create a new Instance of UILabel and add it to your view.
Im not sure about the syntax.
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
label.text = #"your text";
[self.view addSubview:label]
The Simplest way is
UILabel *yourLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 20];
[yourLabel setTextColor:[UIColor blackColor]];
[yourLabel setBackgroundColor:[UIColor clearColor]];
[yourLabel setFont:[UIFont fontWithName: #"Trebuchet MS" size: 14.0f]];
[yourSuperView addSubview:yourLabel];
And if you want to hide till user press the Button. You can do
[yourLabel setHidden:YES];

Unable to use Custom Font in UIButton

I am trying to use a custom font in my application, which is of ttf format. In the Project settings, I have addd that font name like below .
And I have added that font in my resources folder like below
And the font Which I am trying to use is this one
_enterButton.titleLabel.font = [UIFont fontWithName:#"Venus Rising" size:45.0];
If I use Arial or some other font, it works fine. But when I am trying to use this font, it is not at all working. Can anyone tell me why ??
I downloaded the font and as I thought it has different name than what is the name of the file. Look at this image.
Also don't forget on adding the name to the Info.plist of your app, under the key "Fonts provided by application". Hope it helps! :)
You missed extension of font in info.plist, I mean in Info.plist, "Fonts provided by application" you need to set "Venus Rising.ttf" then your problem will be solved
I encountered the same problem few days ago. For me the the font name was different from the ttf file name.
Try this loop to check all the font available in your app :
for (id familyName in [UIFont familyNames]) {
NSLog(#"family name : %#",familyName);
for (id font in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(#" %#",font);
}
}
In your case, Venus Rising should appear as a family name but the exact name of the font you should use in your code may be VenusRisingRegular or something like that.
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 240, 40)];
[label1 setFont: [UIFont fontWithName: #"Grinched" size:24]];
[label1 setText:#"Grinched Font"];
[[self view] addSubview:label1];
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 80, 240, 40)];
[label2 setFont: [UIFont fontWithName: #"Energon" size:18]];
[label2 setText:#"Energon Font"];
[[self view] addSubview:label2];
Please try this.
It's may help to you

iOS Fonts: How to display Coptic Font in iOS

I have to display coptic font on one of my apps. I did a research and found that it is not supported on iOS. This is the website I referred to.. http://iosfonts.com/
Is there a way I could show it on UIWebView or UITextView?
Looking forward for some solutions..
Providing custom font file that can display the coptic font.
Add the font file (xxx.ttf) into your project.
Add "Fonts provided by application" in info.plist. Add the font file name(xxx.ttf) you needed into that array.
Use it as [UIFont fontWithName:fontName size:size];
This fontName is not the filename (eg. xxx.ttf, not xxx for this case), you should open your ttf file and see the name of it.
following code is use when the inserting the after installing the font into the project.
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 240, 40)];
[label1 setFont: [UIFont fontWithName: #"Grinched" size:24]];
[label1 setText:#"Grinched Font"];
[[self view] addSubview:label1];
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 80, 240, 40)];
[label2 setFont: [UIFont fontWithName: #"Energon" size:18]];
[label2 setText:#"Energon Font"];
[[self view] addSubview:label2];
And more detail and tutorial regarding the custom font then goto Reference link here.

How to change the uitextview font size

can any one help to change the font size in UITextView.
[textView setFont:[UIFont fontWithName:#"ArialMT" size:30]];
I use this one but it doesn't work.
Have you bind textView with xib or allocated textView?
If yes,
You can use following code to check whether this works
[textView setFont:[UIFont boldSystemFontOfSize:15]];
or
[textView setFont:[UIFont systemFontOfSize:15]];
Check, if "Selectable" is checked in the xib/Storyboard attribute inspector. If it's not selectable, the size wont be changed
Swift 4.0
textField.font = UIFont.systemFont(ofSize: 17.0)
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[textView setFont: [UIFont fontWithName:#"ArialMT" size:30]];
textView.text = #"test my font size";
[self.view addSubview:textView];
[textView release];
Your code is correct. The problem is from other part of your code. Provide more details about your textView
Set custom font and size in Swift:
textView.font = UIFont(name: "ArialMT", size: 20)
Use this:
UITextView *myTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
myTextView.font = [UIFont fontWithName:#"arial" size:14];
Here is for swift 3.0
textview.font = UIFont(name: textview.font.fontName, size: 18)
I tried it the same way like you with
[textView setFont:[UIFont fontWithName:kFontName size:kFontSize]];
I set the UITextView inside ViewDidLoad. My problem was, I transformed my view:
[_viewEnd setTransform:CGAffineTransformMakeScale(0.0, 0.0)];
My problem was solved with setting the properties of the UITextView after transforming my UIView which includes the UITextView.

Setting truncation mode for UINavigation title text

I want to configure the truncation mode for the text that appears in UINavigationItem.
I've come across a couple of different solutions of configuring the font size but not sure how to make use of the UILineBreakModeHeadTruncation that exists on NSString.
How I've been able to configure the font size:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
[label setFont:[UIFont boldSystemFontOfSize:16.0]];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor whiteColor]];
[label setText:self.title];
[self.navigationController.navigationBar.topItem setTitleView:label];
[label release];
(Based on the recommendation from here)
If I call this in loadView or viewDidLoad, it seems to work but outside of that method, after the view has been loaded, it doesn't seem to work. Not sure why though.
What have you tried, and what's not working? You should be able to do:
label.lineBreakMode = UILineBreakModeHeadTruncation;
Or to wrap to multiple lines:
label.lineBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 0;