Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Code by John Cromartie is a good stuff. Simple and laconic. </p> <p>Just keep in mind some fonts are <strong>bold</strong> or <em>italic</em>. So you probably have to pass 2 (or 3) params: for regular font (as it is now), for bold font and for the italic one. Besides you have to detect if the current font is bold, etc. So there is a bit enhanced piece of code below. </p> <p>However, it can work wrong on iOS7 because user can set his own fonts and, as a result, weight / style detection won't work properly. </p> <pre><code>@implementation UIView (JPCSetFont) - (void)jpc_setAllFonts:(UIFont*)regular bold:(UIFont*)bold { if ([self respondsToSelector:@selector(setFont:)]) { UIFont *oldFont = [self valueForKey:@"font"]; UIFont *newFont; // for iOS6 NSRange isBold = [[oldFont fontName] rangeOfString:@"Bold" options:NSCaseInsensitiveSearch]; // for iOS7 (is device owner didn't change it!) NSRange isMedium = [[oldFont fontName] rangeOfString:@"MediumP4" options:NSCaseInsensitiveSearch]; if (isBold.location==NSNotFound &amp;&amp; isMedium.location==NSNotFound) { newFont = [regular fontWithSize:oldFont.pointSize]; } else { newFont = [bold fontWithSize:oldFont.pointSize]; } // TODO: there are italic fonts also though [self setValue:newFont forKey:@"font"]; } for (UIView *subview in self.subviews) { [subview jpc_setAllFonts:regular bold:bold]; } } @end </code></pre> <p><a href="https://github.com/iutinvg/ZZLib/blob/master/ZZLib/UIView%2BZZFontSetter.h" rel="nofollow">https://github.com/iutinvg/ZZLib/blob/master/ZZLib/UIView%2BZZFontSetter.h</a> <a href="https://github.com/iutinvg/ZZLib/blob/master/ZZLib/UIView%2BZZFontSetter.m" rel="nofollow">https://github.com/iutinvg/ZZLib/blob/master/ZZLib/UIView%2BZZFontSetter.m</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload