I am using size classes
in my storyboard
to create adaptive layout and I have attributed UILabel
s in it. Now I want to change the font size for iPad of these labels but it seems that size classes
for UILabel
with attributed text is not available in IB
. So the question is how to change the font size of a UILabel
with attributed string.
Asked
Active
Viewed 713 times
1

Narender Tak
- 241
- 2
- 12
-
check this....https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/ChangingtheFontforaSizeClass.html – Bhavin Bhadani Jun 12 '15 at 10:42
-
I saw it....but the separate size class to change font is available for a label only if it is in plain mode and not attributed. – Narender Tak Jun 12 '15 at 11:00
-
did you want different font size or different font family for sizeClasses? – Rizwan Shaikh Jun 12 '15 at 12:11
1 Answers
1
As per the Wes said:-
You should take a look at AliSoftware's OHAttributedLabel. It is a subclass of UILabel that draws an NSAttributedString and also provides convenience methods for setting the attributes of an NSAttributedString from UIKit classes.
From the sample provided in the repo:
#import "NSAttributedString+Attributes.h"
#import "OHAttributedLabel.h"
/**(1)** Build the NSAttributedString *******/
NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:@"Hello World!"];
// for those calls we don't specify a range so it affects the whole string
[attrStr setFont:[UIFont systemFontOfSize:12]];
[attrStr setTextColor:[UIColor grayColor]];
// now we only change the color of "Hello"
[attrStr setTextColor:[UIColor redColor] range:NSMakeRange(0,5)];
/**(2)** Affect the NSAttributedString to the OHAttributedLabel *******/
myAttributedLabel.attributedText = attrStr;
// Use the "Justified" alignment
myAttributedLabel.textAlignment = UITextAlignmentJustify;
// "Hello World!" will be displayed in the label, justified, "Hello" in red and " World!" in gray.
Note: In iOS 6+ you can render attributed strings using the attributedText property of UILabel.
please check this question for better understand:-
Iphone/Ipad Nsattributed string
EDIT
You should also check this link to change the size of font.
You should modify it according to your requirement. like if you don't need dynamicaly then dont use method.bumpFontSize
etc.

Community
- 1
- 1

Badal Shah
- 7,541
- 2
- 30
- 65
-
I have set my label as attributed instead of plain and now I want to change its font size....I am not doing any thing to this label with the code. – Narender Tak Jun 12 '15 at 10:58
-
-
As I said earlier I haven't done anything in code related to the label....I am setting the text property of UILabel as attributed instead of plain(default) in storyboard. – Narender Tak Jun 12 '15 at 11:10