AtWork
AtWork

Reputation: 1291

Font size issue in iOS

I am trying to set the font of the label as per follow but it gives me zero CGSize for that.

UIFont *abbrFont = [UIFont fontWithName:@"Helvetica Cyrillic Bold_5" size:50]; //Helvetica Cyrillic Bold_5 added Custom Font

CGSize abbrSizeOfString = [_addbrTitle sizeWithFont:abbrFont];//_addbrTitle is a NSString
NSLog(@"%f %f",abbrSizeOfString.width,abbrSizeOfString.height); //Everytime Prints (0.000,0.000)

Help me to solve this.

Thank you.

Upvotes: 0

Views: 275

Answers (6)

Sarthak Patel
Sarthak Patel

Reputation: 129

NSURL *fontURL = [NSURL URLWithString:[[NSBundle mainBundle]pathForResource:@"your_font_name"  ofType:@"TTF"]];

for example:

NSURL *fontURL2 = [NSURL URLWithString:[[NSBundle mainBundle]pathForResource:@"segoe_semi_bold" ofType:@"TTF"]];

 NSURL *fontURL2 = [NSURL URLWithString:[[NSBundle mainBundle]pathForResource:@"segoe_semi_bold" ofType:@"TTF"]];

now make add url to array

NSArray *arrFont =[[NSArray alloc]initWithObjects:fontURL1,fontURL2, nil];


int result =CTFontManagerRegisterFontsForURLs((CFArrayRef)arrFont, kCTFontManagerScopeUser, nil);
if(result)
{
  NSLog("Font Install successfully");
}

now you can get font

Upvotes: 0

srinivas n
srinivas n

Reputation: 640

Your font name is not current follow this IOS supporting fonts list and Font name

http://iosfonts.com/

Upvotes: 0

Ravindhiran
Ravindhiran

Reputation: 5384

Try this,

UIFont *abbrFont = [UIFont fontWithName:@"Helvetica" size:50]; //Helvetica Cyrillic Bold_5 added Custom Font
CGSize abbrSizeOfString = [_addbrTitle.text sizeWithFont:abbrFont];//_addbrTitle is a Label
NSLog(@"%f %f",abbrSizeOfString.width,abbrSizeOfString.height); //E

Upvotes: 1

Shehbaz Khan
Shehbaz Khan

Reputation: 2000

change your font name to some other built in font name then try like this

yourLabel.font=[UIFont fontWithName:@"Helvetica" size:16];

Upvotes: 0

Devel
Devel

Reputation: 449

UILabel *_addbrTitle = [[UILabel alloc] init];
[_addbrTitle setText:@"Hello"];
UIFont *abbrFont = [UIFont fontWithName:@"Helvetica" size:50]; //Helvetica Cyrillic Bold_5 added Custom Font
[_addbrTitle setFont:abbrFont];
CGSize abbrSizeOfString = [_addbrTitle.text sizeWithFont:abbrFont];//_addbrTitle is a Label
NSLog(@"%f %f",abbrSizeOfString.width,abbrSizeOfString.height); //Everytime Prints (0.000,0.000)

Font name you have entered in the code does not exists in system. So its printing (0,0) every time. Enter a font name which exists in system it will print the size.

Upvotes: 0

kalyani puvvada
kalyani puvvada

Reputation: 496

You can use this line to set the size for label..

[label setFont:[UIFont fontWithName:@"Helvetica" size:20.0]];

Upvotes: 0

Related Questions