diff --git a/README.md b/README.md index f8cfdd7..4bd6a2c 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ UIFont *myFont = [UIFont dynamicFontWithName:@"Courier" baseSize:16.0f]; NSInteger textDelta = [[UIApplication sharedApplication] preferredFontSizeDelta]; ``` -## AttributedText Support +## `NSAttributedString` Support SSDynamicText supports attributed text, all you have to do is set your attributed text to new property dynamicAttributedText. diff --git a/SSDynamicText/NSAttributedString+SSTextSize.h b/SSDynamicText/NSAttributedString+SSTextSize.h index 47a791a..599f071 100644 --- a/SSDynamicText/NSAttributedString+SSTextSize.h +++ b/SSDynamicText/NSAttributedString+SSTextSize.h @@ -1,6 +1,6 @@ // // NSAttributedString+SSTextSize.h -// Pods +// SSDynamicText // // Created by Remigiusz Herba on 28/08/15. // @@ -10,6 +10,13 @@ @interface NSAttributedString (SSTextSize) +/** + * Creates NSAttributedString with each font size changed by delta + * @param delta The size by which you want to change the font. + * A negative number will decrease font size. + * A positive number will increase font size. + * @return new NSAttributedString object with font size changed by delta. + */ - (NSAttributedString *)ss_attributedStringWithAdjustedFontSizeWithDelta:(NSInteger)delta; @end diff --git a/SSDynamicText/NSAttributedString+SSTextSize.m b/SSDynamicText/NSAttributedString+SSTextSize.m index cf5e0ca..faed3a8 100644 --- a/SSDynamicText/NSAttributedString+SSTextSize.m +++ b/SSDynamicText/NSAttributedString+SSTextSize.m @@ -1,6 +1,6 @@ // // NSAttributedString+SSTextSize.m -// Pods +// SSDynamicText // // Created by Remigiusz Herba on 28/08/15. // diff --git a/SSDynamicText/SSDynamicAttributedTextSizable.h b/SSDynamicText/SSDynamicAttributedTextSizable.h index 38c0e85..1eb0cfe 100644 --- a/SSDynamicText/SSDynamicAttributedTextSizable.h +++ b/SSDynamicText/SSDynamicAttributedTextSizable.h @@ -1,6 +1,6 @@ // // SSDynamicAttributedTextSizable.h -// Pods +// SSDynamicText // // Created by Remigiusz Herba on 15/09/15. // @@ -10,12 +10,16 @@ @protocol SSDynamicAttributedTextSizable -/* - TextView and TextField sometimes calls setAttributedText even when we work with normal Text. - Framework is using it under the hood sometimes after layouts or even setText calls it. Because of that we cannot override - default attributeText setter to change font, sometimes it change font at random. +/** + * TextView and TextField sometimes calls setAttributedText even when we work with normal Text. + * Framework is using it under the hood sometimes after layouts or even setText calls it. Because of that we cannot override + * default attributeText setter to change font, sometimes it change font at random. + * + * This is used to set attributedText which will be dynamicaly changed with font size changes. + * Updating this will change attributedText to dynamicAttributedText + font sizes changed with delta. + * @return original dynamicAttributedText value. To check current attributedText font sizes use @property attributedText + * */ - @property (nonatomic, copy) NSAttributedString *dynamicAttributedText; @end diff --git a/SSDynamicText/SSDynamicButton.h b/SSDynamicText/SSDynamicButton.h index 39507d2..cd4f0e5 100644 --- a/SSDynamicText/SSDynamicButton.h +++ b/SSDynamicText/SSDynamicButton.h @@ -8,8 +8,8 @@ #import -/* - While creating this button in xib, don't forget to change it type to Custom !! +/** + * While creating this button in xib, don't forget to change it type to Custom !! */ @interface SSDynamicButton : UIButton diff --git a/SSDynamicText/SSDynamicButton.m b/SSDynamicText/SSDynamicButton.m index 9eb45ea..ea88edf 100644 --- a/SSDynamicText/SSDynamicButton.m +++ b/SSDynamicText/SSDynamicButton.m @@ -49,6 +49,7 @@ - (instancetype)initWithFrame:(CGRect)frame { - (void)awakeFromNib { [super awakeFromNib]; + NSAssert(self.buttonType == UIButtonTypeCustom, @"Change SSDynamicButton.buttonType to UIButtonTypeCustom in your nib"); NSString *fontName; CGFloat baseSize = 0; diff --git a/SSDynamicText/SSDynamicLabel.m b/SSDynamicText/SSDynamicLabel.m index b7049fd..3b47401 100644 --- a/SSDynamicText/SSDynamicLabel.m +++ b/SSDynamicText/SSDynamicLabel.m @@ -37,7 +37,7 @@ - (void)setFont:(UIFont *)font { - (instancetype)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { - [self startObservingTextSizeChanged]; + [self startObservingTextSizeChanges]; } return self; @@ -47,7 +47,7 @@ - (void)awakeFromNib { [super awakeFromNib]; [self setupBaseFontBasedOnCurrentFont]; - [self startObservingTextSizeChanged]; + [self startObservingTextSizeChanges]; } + (instancetype)labelWithFont:(NSString *)fontName baseSize:(CGFloat)size { @@ -100,7 +100,7 @@ - (void)setupBaseFontBasedOnCurrentFont { size:baseSize]); } -- (void)startObservingTextSizeChanged { +- (void)startObservingTextSizeChanges { [self ss_startObservingTextSizeChangesWithBlock:self.textSizeChanger.changeHandler]; } diff --git a/SSDynamicText/SSDynamicTextField.m b/SSDynamicText/SSDynamicTextField.m index 32654e3..4710b58 100644 --- a/SSDynamicText/SSDynamicTextField.m +++ b/SSDynamicText/SSDynamicTextField.m @@ -37,7 +37,7 @@ - (void)setFont:(UIFont *)font { - (instancetype)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { - [self startObservingTextSizeChanged]; + [self startObservingTextSizeChanges]; } return self; @@ -47,7 +47,7 @@ - (void)awakeFromNib { [super awakeFromNib]; [self setupBaseFontBasedOnCurrentFont]; - [self startObservingTextSizeChanged]; + [self startObservingTextSizeChanges]; } + (instancetype)textFieldWithFont:(NSString *)fontName baseSize:(CGFloat)size { @@ -100,7 +100,7 @@ - (void)setupBaseFontBasedOnCurrentFont { size:baseSize]); } -- (void)startObservingTextSizeChanged { +- (void)startObservingTextSizeChanges { [self ss_startObservingTextSizeChangesWithBlock:self.textSizeChanger.changeHandler]; } diff --git a/SSDynamicText/SSDynamicTextSizeChanger.h b/SSDynamicText/SSDynamicTextSizeChanger.h index 74789e9..d4665b0 100644 --- a/SSDynamicText/SSDynamicTextSizeChanger.h +++ b/SSDynamicText/SSDynamicTextSizeChanger.h @@ -1,6 +1,6 @@ // // SSDynamicTextSizeChanger.h -// Pods +// SSDynamicText // // Created by Remigiusz Herba on 15/09/15. // @@ -12,10 +12,26 @@ @interface SSDynamicTextSizeChanger : NSObject +/** + * The default font descriptor used by view. + * Its size is adjusted up (or down) based on the user's preferred text size. + * Updating this will change the view's font. + */ @property (nonatomic, strong) UIFontDescriptor *defaultFontDescriptor; + +/** + * The default block called by view when font size change. + */ @property (nonatomic, readonly) SSTextSizeChangedBlock changeHandler; +/** + * Block which is called when SSDynamicTextSizeChanger want to change font, view should configure this block. + */ @property (nonatomic, copy) void(^fontChangeBlock)(UIFont *font); + +/** + * Block which is called when SSDynamicTextSizeChanger want to change attributedText, view should configure this block. + */ @property (nonatomic, copy) void(^attributedTextChangeBlock)(NSAttributedString *attributedString); @end diff --git a/SSDynamicText/SSDynamicTextSizeChanger.m b/SSDynamicText/SSDynamicTextSizeChanger.m index 44ebae5..2a1e987 100644 --- a/SSDynamicText/SSDynamicTextSizeChanger.m +++ b/SSDynamicText/SSDynamicTextSizeChanger.m @@ -1,6 +1,6 @@ // // SSDynamicTextSizeChanger.m -// Pods +// SSDynamicText // // Created by Remigiusz Herba on 15/09/15. // diff --git a/SSDynamicText/SSDynamicTextView.m b/SSDynamicText/SSDynamicTextView.m index e8a844b..d20ddbc 100644 --- a/SSDynamicText/SSDynamicTextView.m +++ b/SSDynamicText/SSDynamicTextView.m @@ -37,7 +37,7 @@ - (void)setFont:(UIFont *)font { - (instancetype)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { - [self startObservingTextSizeChanged]; + [self startObservingTextSizeChanges]; } return self; @@ -47,7 +47,7 @@ - (void)awakeFromNib { [super awakeFromNib]; [self setupBaseFontBasedOnCurrentFont]; - [self startObservingTextSizeChanged]; + [self startObservingTextSizeChanges]; } + (instancetype)textViewWithFont:(NSString *)fontName baseSize:(CGFloat)size { @@ -100,7 +100,7 @@ - (void)setupBaseFontBasedOnCurrentFont { size:baseSize]); } -- (void)startObservingTextSizeChanged { +- (void)startObservingTextSizeChanges { [self ss_startObservingTextSizeChangesWithBlock:self.textSizeChanger.changeHandler]; }