Hi I am using below code to use custom font style for label text. I've installed it and work fine but the problem is that the size of text does not change. I've tried more times with different sizes. I don't know what should do
self.saveButton_label.text = NSLocalizedString(#"Saved", nil);
self.saveButton_label.font = [UIFont fontWithName:#"Helvetica Neue LT Pro" size: 13.0];
I believe the issue lies with one of the steps you need to take when adding a custom font to your project, you probably are not noticing the difference because Helvetica Neue is also the default font, which I believe is used if you were to assign nil to UILabel as the font.
I suggest following this guide, I've used it as a checklist myself when using custom fonts and it has worked, especially take not of the naming, the name you have to use in code might not be the one you see in FontBook or when using Preview on the font.
Try this code, In your code you are missing "-" with font name.
self.saveButton_label.text = #"Saved";
[self.saveButton_label setFont:[UIFont fontWithName:#"Helvetica-Neue-LT-Pro size:13.0f]];
also you can use below fonts.
HelveticaNeueLTPro-MdCn
HelveticaNeueLTPro-BdCn
Hope it will work for you.
Related
I'm loading in text from a plist and displaying it within my app. Ideally I want to be able to specify more complex formatting such as italics, bold and superscript text, and display it in a custom label such as TTTAttributedLabel.
Are there any available libraries to parse a string in a given format (preferably a simple text format such as Markdown or Textile) into an NSAttributedString? I am aware that solutions are available for parsing RTF and HTML, but this is overkill for my needs - plus I'd like the text to be easily written by hand.
Edit: this is for iOS/UIKit
Caught your edit. For iOS/UIKit there is a project out there called NSAttributedString+HTML that attempts to simulate the functionality available on OS X. On OS X, you would just use some minor HTML to format the string and then parse it into NSAttributedString (or objects, or websites, or files, etc.).
The project I mentioned above attempts to offer the same extensions on iOS. I don't know why, after 6 major releases of iOS, it still lacks such rich tools and pushes all the weight on UIWebView (over WebKit) but that's how it is.
I've just added an NSString to NSAttributedString lightweight markup parser to MGBoxKit. It's not Markdown or Textile but it's very similar. So far it supports bold, italics, underline, monospacing, and coloured text.
The MGMushParser class could be used standalone, and is fairly easy to extend.
NSString *markup = #"**bold**, //italics//, __underlining__, and `monospacing`, and {#0000FF|coloured text}";
UIFont *baseFont = [UIFont fontWithName:#"HelveticaNeue" size:18];
UIColor *textColor = UIColor.whiteColor;
myLabel.attributedString = [MGMushParser attributedStringFromMush:markup
font:baseFont color:textColor];
OHAttributedLabel also has a similar markup parser.
I'm trying to add a font into my project to use in a label but it just don't work. Here is what I'm doing:
I copy the font file into my project resources.
Set my plist file with the array key UIAppFonts.
Add my font's name Kingashandwriting.ttf (the real name with the extension
, not the file name) into the array.
Set up my font in the code: UIFont *font= [UIFont fontWithName:#"Kingashandwriting" size:15];
Set it into my label: [self.myLabel setFont:font];
myLabel is an IBOutlet that is linked with a label in interface builder.
I'm using Xcode 4.3.3
Am i missing something?
I remember that I ran into this same problem when implementing custom fonts into my application. I thought that I had the official name right but it was giving me problems.
My advice is to open up the file in font book and look at the top of the window and see what that name says. Then format it exactly how you see it in your fontWithName: method.
Here's an image of what you're looking for:
http://i.stack.imgur.com/uOZy6.png
Then your font method would look like this (based on the font in the image):
UIFont *font= [UIFont fontWithName:#"BankGothic Lt BT" size:15];
For further information, in my application my file is named bankgthl.ttf and I have that file name added into my plist array. But when I am setting the font in my code I call it the same as above using the name seen in font book and it is all working fine.
I have a jar I include with my application with some fonts. If I paste around
<font fontName="NimbusSansGlobal Light" size="12" pdfFontName="NimbusSansGlobal Light" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
into all my text elements, PDF output works fine. If I switch them all to use a style which defines the font as such:
<style name="SansFontStyle" isDefault="true" pdfFontName="NimbusSansGlobal Light" pdfEncoding="Identity-H" isPdfEmbedded="true"/>, then the font can't be found by the JRLoader when I try to generate reports. Interesting enough, if I use JRLoader within my application directly, the font is found fine.
Why would styles break PDF export?
Using Font Extensions should solve this problem.
Once you use font extensions, then you can set the font in the text element or in the style. You will not specify pdfFontName, pdfEncoding, or isPdfEmbedded in the report. That gets specified in the font extension.
Note: In a strict interpretation, this doesn't actually answer the question. I have no idea why styles work differently from directly setting the fonts. It seems like a bug, but maybe it's unexpected yet intentional for some reason we aren't thinking of. Therefore, I started to enter this as a comment rather than an answer. But it got too long.
Regardless, this should allow you to use styles as you want to. So I expect that it will solve the heart of the problem.
Font extensions are documented in the JasperReports (and iReport) samples and documentation, so it should be pretty easy to use them once you know that you ought to.
I used a special font in my photoshop design,
is it possible to use these fonts natively in the iphone app? or
do I need to convert them into an image first?
If this is the only way to do it, what do you do with dynamic text?
Copy your font file into Resources
In your application .plist create (if it's exist just create a row) a row called "Fonts provided by application" and then in "item 0" copy your font name for example "Ciutadella-Bold.otf" (if there are some spaces in font name, rename it and for example replace all spaces to minus '-')
Then you can define this font in your application:
UIFont *CiutadellaBold = [UIFont fontWithName:#"Ciutadella-Bold" size:17.0f];
And use in for instance in uiLabel:
[uiLabel setFont:CiutadellaBold];
UIFont *font = [UIFont fontWithName:#"MyFont" size:20];
[label setFont:font];
Where "MyFont" would be a TrueType or OpenType file in your project (sans the file extension), and label would be an instance of UILabel.
Yes it is possible with iOS 3.2 and later. You need to have the fonts file, I forget what formats exactly. Add the font file as a resource to your project then add the names of the fonts in the applications info.plist in an array under the raw key 'UIAppFonts' or under the friendly key 'Fonts provided by application'.
Here's a sample application that you can look at - https://files.me.com/tobiasoleary/ey08n1. It prints out the all the fonts accessible to the application. Two fonts have been added Flames and Firestarter.
This is by far the easiest way to add custom fonts to application. If you need to support custom fonts for iOS before 4.0 see http://github.com/zynga/FontLabel/tree/master
This question has been asked before here: Can I embed a custom font in an iPhone application?.
Note :
The parameter of “fontWithName” must be the real name of the font, not the name of the file. If you open your ttf file with the Mac Font Book, you will directly see its name on top of the window.
I'm building an iPad-Only application. I need to use a custom font with some labels, so I added them to my project. They appear in my application target for "Copy Bundle Resources". I also added their names to my App's -Info.plist file:
<key>UIAppFonts</key>
<array>
<string>font1.ttf</string>
<string>font2.ttf</string>
<string>font3.ttf</string>
<string>font4.ttf</string>
</array>
Even so, when I try to set the font of my labels, it seems to just use the default. I haven't been able to figure out how to overcome this issue. Any assistance would be greatly appreciated.
Edit:
- (void)debug {
NSLog(#"fonts: %#", [UIFont familyNames]);
UIFont *f1 = [UIFont fontWithName:#"Helvetica" size:20];
UIFont *f2 = [UIFont fontWithName:#"font1" size:5];
NSLog(#"f1:%# f2:%#", f1, f2);
}
And the output: http://pastie.org/1323195
How are you setting the font?
You need to use it as follows....
UIFont *myCustomFont = [UIFont fontWithName:#"font1" size:30];
The solution ended up being to use a different font. I opened the font with FontForge and got this warning:
This font is marked with an FSType of 2 (Restricted License). That means it is not editable without the permission of the legal owner.
This seems to be the cause of my issues. I downloaded a free version of the font I was trying to use (luckily it was available for free) and everything started working perfectly.