Skip to content

Commit e347735

Browse files
committed
Merge pull request #18 from Remki/AddedAttributedTexts
Added support for attributedText.
2 parents e50155b + 9c903a2 commit e347735

11 files changed

+50
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ UIFont *myFont = [UIFont dynamicFontWithName:@"Courier" baseSize:16.0f];
113113
NSInteger textDelta = [[UIApplication sharedApplication] preferredFontSizeDelta];
114114
```
115115

116-
## AttributedText Support
116+
## `NSAttributedString` Support
117117

118118
SSDynamicText supports attributed text, all you have to do is set your attributed text to new property dynamicAttributedText.
119119

SSDynamicText/NSAttributedString+SSTextSize.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// NSAttributedString+SSTextSize.h
3-
// Pods
3+
// SSDynamicText
44
//
55
// Created by Remigiusz Herba on 28/08/15.
66
//
@@ -10,6 +10,13 @@
1010

1111
@interface NSAttributedString (SSTextSize)
1212

13+
/**
14+
* Creates NSAttributedString with each font size changed by delta
15+
* @param delta The size by which you want to change the font.
16+
* A negative number will decrease font size.
17+
* A positive number will increase font size.
18+
* @return new NSAttributedString object with font size changed by delta.
19+
*/
1320
- (NSAttributedString *)ss_attributedStringWithAdjustedFontSizeWithDelta:(NSInteger)delta;
1421

1522
@end

SSDynamicText/NSAttributedString+SSTextSize.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// NSAttributedString+SSTextSize.m
3-
// Pods
3+
// SSDynamicText
44
//
55
// Created by Remigiusz Herba on 28/08/15.
66
//
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SSDynamicAttributedTextSizable.h
3-
// Pods
3+
// SSDynamicText
44
//
55
// Created by Remigiusz Herba on 15/09/15.
66
//
@@ -10,12 +10,16 @@
1010

1111
@protocol SSDynamicAttributedTextSizable <NSObject>
1212

13-
/*
14-
TextView and TextField sometimes calls setAttributedText even when we work with normal Text.
15-
Framework is using it under the hood sometimes after layouts or even setText calls it. Because of that we cannot override
16-
default attributeText setter to change font, sometimes it change font at random.
13+
/**
14+
* TextView and TextField sometimes calls setAttributedText even when we work with normal Text.
15+
* Framework is using it under the hood sometimes after layouts or even setText calls it. Because of that we cannot override
16+
* default attributeText setter to change font, sometimes it change font at random.
17+
*
18+
* This is used to set attributedText which will be dynamicaly changed with font size changes.
19+
* Updating this will change attributedText to dynamicAttributedText + font sizes changed with delta.
20+
* @return original dynamicAttributedText value. To check current attributedText font sizes use @property attributedText
21+
*
1722
*/
18-
1923
@property (nonatomic, copy) NSAttributedString *dynamicAttributedText;
2024

2125
@end

SSDynamicText/SSDynamicButton.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#import <UIKit/UIKit.h>
1010

11-
/*
12-
While creating this button in xib, don't forget to change it type to Custom !!
11+
/**
12+
* While creating this button in xib, don't forget to change it type to Custom !!
1313
*/
1414
@interface SSDynamicButton : UIButton
1515

SSDynamicText/SSDynamicButton.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
4949
- (void)awakeFromNib {
5050
[super awakeFromNib];
5151

52+
NSAssert(self.buttonType == UIButtonTypeCustom, @"Change SSDynamicButton.buttonType to UIButtonTypeCustom in your nib");
5253
NSString *fontName;
5354
CGFloat baseSize = 0;
5455

SSDynamicText/SSDynamicLabel.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ - (void)setFont:(UIFont *)font {
3737

3838
- (instancetype)initWithFrame:(CGRect)frame {
3939
if ((self = [super initWithFrame:frame])) {
40-
[self startObservingTextSizeChanged];
40+
[self startObservingTextSizeChanges];
4141
}
4242

4343
return self;
@@ -47,7 +47,7 @@ - (void)awakeFromNib {
4747
[super awakeFromNib];
4848

4949
[self setupBaseFontBasedOnCurrentFont];
50-
[self startObservingTextSizeChanged];
50+
[self startObservingTextSizeChanges];
5151
}
5252

5353
+ (instancetype)labelWithFont:(NSString *)fontName baseSize:(CGFloat)size {
@@ -100,7 +100,7 @@ - (void)setupBaseFontBasedOnCurrentFont {
100100
size:baseSize]);
101101
}
102102

103-
- (void)startObservingTextSizeChanged {
103+
- (void)startObservingTextSizeChanges {
104104
[self ss_startObservingTextSizeChangesWithBlock:self.textSizeChanger.changeHandler];
105105
}
106106

SSDynamicText/SSDynamicTextField.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ - (void)setFont:(UIFont *)font {
3737

3838
- (instancetype)initWithFrame:(CGRect)frame {
3939
if ((self = [super initWithFrame:frame])) {
40-
[self startObservingTextSizeChanged];
40+
[self startObservingTextSizeChanges];
4141
}
4242

4343
return self;
@@ -47,7 +47,7 @@ - (void)awakeFromNib {
4747
[super awakeFromNib];
4848

4949
[self setupBaseFontBasedOnCurrentFont];
50-
[self startObservingTextSizeChanged];
50+
[self startObservingTextSizeChanges];
5151
}
5252

5353
+ (instancetype)textFieldWithFont:(NSString *)fontName baseSize:(CGFloat)size {
@@ -100,7 +100,7 @@ - (void)setupBaseFontBasedOnCurrentFont {
100100
size:baseSize]);
101101
}
102102

103-
- (void)startObservingTextSizeChanged {
103+
- (void)startObservingTextSizeChanges {
104104
[self ss_startObservingTextSizeChangesWithBlock:self.textSizeChanger.changeHandler];
105105
}
106106

SSDynamicText/SSDynamicTextSizeChanger.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SSDynamicTextSizeChanger.h
3-
// Pods
3+
// SSDynamicText
44
//
55
// Created by Remigiusz Herba on 15/09/15.
66
//
@@ -12,10 +12,26 @@
1212

1313
@interface SSDynamicTextSizeChanger : NSObject <SSDynamicAttributedTextSizable>
1414

15+
/**
16+
* The default font descriptor used by view.
17+
* Its size is adjusted up (or down) based on the user's preferred text size.
18+
* Updating this will change the view's font.
19+
*/
1520
@property (nonatomic, strong) UIFontDescriptor *defaultFontDescriptor;
21+
22+
/**
23+
* The default block called by view when font size change.
24+
*/
1625
@property (nonatomic, readonly) SSTextSizeChangedBlock changeHandler;
1726

27+
/**
28+
* Block which is called when SSDynamicTextSizeChanger want to change font, view should configure this block.
29+
*/
1830
@property (nonatomic, copy) void(^fontChangeBlock)(UIFont *font);
31+
32+
/**
33+
* Block which is called when SSDynamicTextSizeChanger want to change attributedText, view should configure this block.
34+
*/
1935
@property (nonatomic, copy) void(^attributedTextChangeBlock)(NSAttributedString *attributedString);
2036

2137
@end

SSDynamicText/SSDynamicTextSizeChanger.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SSDynamicTextSizeChanger.m
3-
// Pods
3+
// SSDynamicText
44
//
55
// Created by Remigiusz Herba on 15/09/15.
66
//

0 commit comments

Comments
 (0)