0

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.

AtWork
  • 1,283
  • 1
  • 14
  • 34

6 Answers6

1

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
Ravindhiran
  • 5,304
  • 9
  • 50
  • 82
0

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

[label setFont:[UIFont fontWithName:@"Helvetica" size:20.0]];
kalyani puvvada
  • 496
  • 4
  • 12
0
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.

Devel
  • 449
  • 3
  • 9
0

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

yourLabel.font=[UIFont fontWithName:@"Helvetica" size:16];
Shehbaz Khan
  • 1,892
  • 3
  • 24
  • 31
0

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

http://iosfonts.com/

srinivas n
  • 640
  • 4
  • 20
0
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

Arun
  • 3,406
  • 4
  • 30
  • 55
Sarthak Patel
  • 129
  • 2
  • 8