sagarkothari
sagarkothari

Reputation: 24820

Setting UILabel - Font through code generates error

See following code. Because it works perfectly.

- (void)viewDidLoad {
[super viewDidLoad];
// title label - tip
UILabel *tmp=[[UILabel alloc] initWithFrame:CGRectMake(50, 50, 200, 200)]; 
tmp.textColor=[UIColor colorWithRed:(14.0/255.0) green:(105.0/255) blue:(128.0/255) alpha:1.0];
[tmp setFont:[UIFont fontWithName:@"Arial" size:18]]; tmp.text=@"sagar";
tmp.backgroundColor=[UIColor clearColor]; [self.view addSubview:tmp]; [tmp release];
}

Now, see following code. Because it doesn't work. See there is no difference between both of these code.

- (void)viewDidLoad {
[super viewDidLoad];
// title label - tip
UILabel *tmp=[[UILabel alloc] initWithFrame:CGRectMake(50, 50, 200, 200)]; 
tmp.textColor=[UIColor colorWithRed:(14.0/255.0) green:(105.0/255) blue:(128.0/255) alpha:1.0];
[tmp setFont:[UIFont fontWithName:@"Arial Black" size:18]]; tmp.text=@"sagar";
tmp.backgroundColor=[UIColor clearColor]; [self.view addSubview:tmp]; [tmp release];
}

I have just mentioned #Arial Black# instead #Arial#.

I would like to know why it isn't working.

How many different kind of font does iPhone support?

Is there any list?

How to set a font name to a UILabel or to any control ? (font which has space within there name)

Upvotes: 10

Views: 37363

Answers (3)

Josh Brown
Josh Brown

Reputation: 53133

There are plenty of font apps in the App Store to see all the fonts - one of which is iFonts, an app I developed so I could email the list of fonts to someone else on the team.

Upvotes: 0

unknown
unknown

Reputation:

Try @"Arial-BoldMT"

Besides, you could always make yourself a list of available fonts:

for( NSString *familyName in [UIFont familyNames] ) {
  for( NSString *fontName in [UIFont fontNamesForFamilyName:familyName] ) {
    NSLog(@"%@", fontName);
  }
}

Upvotes: 12

fbrereto
fbrereto

Reputation: 35935

Here is a list of fonts available in the iPhone OS. It would seem Arial Black is not among them.

Upvotes: 22

Related Questions