creating bold text in pdf from ipad - ipad

I have an iPad app that creates a pdf and works fine however I am trying to get the headings bold.
Currently I have:
UIFont *font = [UIFont fontwithname:#"arial" size 12];
I would like to know what I need to add to make the text bold as well.
Many thanks

This does the trick:
UIFont *font = [UIFont fontWithName:#"Arial-BoldMT" size:12.0];

Related

Change UITableViewCell Font in iOS 8 and swift

I'm trying to change the font for my uitableviewcells,
I'm trying to use this at the moment with not success:
cell.textLabel.font = [UIFont .preferredFontForTextStyle("Avenir")];
Now i've read a lot on this and it seems I should use this instead :
cell.textLabel.font = [UIFont fontWithName: "Avenir" size:22];
Problem is fontWithName does not seem to exist in iOS 8
any ideas??
thanks
The thing is that this is not Swift (it is a kind of horrifying bastardization of Objective-C):
cell.textLabel.font = [UIFont fontWithName: "Avenir" size:22];
This would be Swift:
cell.textLabel.font = UIFont(name:"Avenir", size:22)
Try the following casting way:
cell.textLabel.font = UIFont(name: "Avenir", size:22);

WatchKit, AttributedString formatting not working

I am building my first WatchKit App and am having troubles with NSAttributedString formatting as it does not seem to work as I'd expect ;)
This is my code:
UIFont *textFont = [UIFont fontWithName:#"Menlo" size:30];
UIFont *hlFont = [UIFont fontWithName:#"Menlo-Bold" size:30];
NSMutableAttributedString *information = [[NSMutableAttributedString alloc]initWithString:#"ADDED AN ENTRY OF " attributes:#{NSFontAttributeName : textFont}];
NSString *amountString = [NSString stringWithFormat:#"%.2f",(-1)*handler.amount.floatValue];
NSNumber *underline = [NSNumber numberWithInt:NSUnderlineStyleSingle];
NSAttributedString *amount = [[NSAttributedString alloc]initWithString:amountString attributes:#{NSFontAttributeName : hlFont, NSUnderlineStyleAttributeName : underline }];
NSAttributedString *to = [[NSMutableAttributedString alloc]initWithString:#" TO " attributes:#{NSFontAttributeName : textFont}];
NSString *categoryString = handler.category;
NSAttributedString *category = [[NSAttributedString alloc]initWithString:categoryString attributes:#{NSFontAttributeName : hlFont, NSUnderlineStyleAttributeName : underline }];
[information appendAttributedString:amount];
[information appendAttributedString:to];
[information appendAttributedString:category];
[_informationLabel setAttributedText:information];
and this the result:
Expectation
10.00 and Stuff should be underlined and in boldface.
Is there something fundamentally different to how attributed strings work on the watch than on iOS? What am I missing?
read through this: https://developer.apple.com/library/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/TextandLabels.html
Solved it, the problem were the fonts #"Menlo".
By using
UIFont *textFont = [UIFont systemFontOfSize:20];
UIFont *hlFont = [UIFont systemFontOfSize:20];
the formatting with underlines works fine.
I don't believe you can programmatically set a label to be bold, italic, underlined....this has to be done through the actual interface in the storyboard.
According to this link
The attributes you can configure are
text
text color
font
min scale
alignment
lines
a potential workaround is to incorporate multiple labels, and set the ones you need to the right format (bold, underlined)

how to change font size of label without changing font family in xcode

how to change font size of label without changing font family in xcode6 ?I am using following line of code:
lblMain.font = [UIFont systemFontOfSize:22];
Here's an example:
lblMain.font = [UIFont fontWithName:#"HelveticaNeue" size:22];
Or - you can even use the current font:
lblMain.font = [lblMain.font fontWithSize:22];
NSString *fontName = lblMain.font.fontName;
CGFloat fontSize = lblMain.font.pointSize;
[lblMain setFont:[UIFont fontWithName:fontName size:NEWSIZE]];
Use following code, if you just want to change font size keeping the same font family:
lblMain.font = [UIFont fontWithName:lblMain.font.fontName size:22.0f];
OR
You can also use this code:
lblMain.font = [lblMain.font fontWithSize:22.0f];
[lblMain setFont:[UIFont fontWithName:#"HelveticaNeue" size:17]];

How to iOS adding custom font with same name but different weight?

I have a problem of adding custom font with same name but different weight like:
[_lblFullName setFont:[UIFont fontWithName:#"Museo Sans 500" size:20]];
[_lblTicket setFont:[UIFont fontWithName:#"Museo Sans 900" size:12]];
I can only make this work by adding only one font weight but i have to rename it Museo Sans and only import one font to bundle and delete the other font. like:
[_lblFullName setFont:[UIFont fontWithName:#"Museo Sans" size:20]];
[_lblTicket setFont:[UIFont fontWithName:#"Museo Sans" size:12]];
But it only allows me one font weight, I need to have to import this two font weight.
Please help.
[_lblFullName setFont:[UIFont fontWithName:#"MuseoSans-500" size:20]];
[_lblTicket setFont:[UIFont fontWithName:#"MuseoSans-900" size:12]];
You can access the names of your custom fonts in the "Museo Sans" family by running:
NSArray *fonts = [UIFont fontNamesForFamilyName:#"Museo Sans"];
for (NSString *fname in fonts) {
UIFont *font = [UIFont fontWithName:fname size:12.0];
NSLog(#"name: %# font: %#", fname, font);
}
Whichever string is logged as the name works when used with fontWithName.
In Swift 2.2, you may want to do like this:
let fonts = UIFont.fontNamesForFamilyName("Museo Sans")
for name in fonts {
let font = UIFont(name: name, size: 12)
print("name: \(font?.fontName) font: \(font)")
}

Adjoining "f" and "l" characters

For some reason, when I display the word "Butterfly" (or anything else with an "fl"), the "f" and the "l" connect at the top (see image below). The font is Century Gothic Bold. This is the code I use to setup the UILabel. The string for the label is retrieved from a plist:
UILabel *label = [[UILabel alloc] init];
label.text = [self.flashcardDelegate.alphabetArr objectAtIndex:index];
label.textColor = [UIColor colorWithRed:.733 green:0 blue:.03137 alpha:1];
label.backgroundColor = [UIColor clearColor];
label.frame = CGRectMake(ipad ? 210.0f : 65.0f,
ipad ? 650.0f : 300.0f,
ipad ? 340.0f : 185.0f,
ipad ? 250.0f : 135.0f);
label.font = [UIFont fontWithName:#"CenturyGothic-Bold" size:ipad ? 200 : 100];
label.textAlignment = UITextAlignmentCenter;
Any idea why this would happen? Thanks.
It's called a ligature, and it's intentional. You can change how the OS renders ligatures by using the kCTLigatureAttributeName attribute if you're using Core Text, or you can use NSLigatureAttributeName if you're using NSAttributedString.
What you're seeing is known as a ligature - the idea was originally to make it easier to handle the kerning on metal blocks for printing presses (to use one glyph for commonly-joined character pairs), but now has persisted into the modern era as a largely stylistic decision.
I'm unsure how to disable it in the API, but hopefully this additional background information can help you find the answer.
Here is a short way of doing this. iOS 6.0+
NSMutableAttributedString *attributedString;
attributedString = [[NSMutableAttributedString alloc] initWithString:label.text];
[attributedString addAttribute:NSLigatureAttributeName value:#0 range:NSMakeRange(0, label.text.length)];
[label.text setAttributedText:attributedString];
[attributedString release];

Resources