How to get the font-size of a UIFont instance?
Or, if someone can implement this method for UIFont?
- (UIFont *)boldFont;
This is an old answer and it's no longer the best solution, please see the accepted answer instead.
-(UIFont *)boldFont{ //First get the name of the font (unnecessary, but used for clarity) NSString *fontName = self.fontName; //Some fonts having -Regular on their names. so we have to remove that before append -Bold / -BoldMT fontName = [[fontName componentsSeparatedByString:@"-"] firstObject]; //Then append "-Bold" to it. NSString *boldFontName = [fontName stringByAppendingString:@"-Bold"]; //Then see if it returns a valid font UIFont *boldFont = [UIFont fontWithName:boldFontName size:self.pointSize]; //If it's valid, return it if(boldFont) return boldFont; //Seems like in some cases, you have to append "-BoldMT" boldFontName = [fontName stringByAppendingString:@"-BoldMT"]; boldFont = [UIFont fontWithName:boldFontName size:self.pointSize]; //Here you can check if it was successful, if it wasn't, then you can throw an exception or something. return boldFont; }
To access the font size from your UIFont instance use
@property(nonatomic, readonly) CGFloat pointSize
There are more property to tell the font size (for cap, small etc...)
capHeight,xHeight,pointSize
Use below to access the bold font
UIFont* myboldFont = [UIFont boldSystemFontOfSize:11];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With