Reputation: 1291
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
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
Reputation: 640
Your font name is not current follow this IOS supporting fonts list and Font name
Upvotes: 0
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
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
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
Reputation: 496
You can use this line to set the size for label..
[label setFont:[UIFont fontWithName:@"Helvetica" size:20.0]];
Upvotes: 0