Skip to content

Commit cb531c5

Browse files
committed
TextField and TextView: support dynamic type
fixed dynamic cell height for text view and calculate height and padding values without using constants;
1 parent 8576565 commit cb531c5

File tree

6 files changed

+18
-14
lines changed

6 files changed

+18
-14
lines changed

InAppSettingsKit.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'InAppSettingsKit'
3-
s.version = '3.8.7'
3+
s.version = '3.8.8'
44
s.summary = 'This iPhone framework allows settings to be in-app in addition to being in the Settings app.'
55

66
s.description = <<-DESC
@@ -16,5 +16,5 @@ InAppSettingsKit (IASK) is an open source solution to easily add in-app settings
1616
s.resource_bundles = {"InAppSettingsKit" => "Sources/InAppSettingsKit/Resources/*"}
1717
s.source_files = "Sources/InAppSettingsKit/**/*.{h,m}"
1818
s.frameworks = "MessageUI", "UIKit"
19-
s.ios.deployment_target = '10.0'
19+
s.ios.deployment_target = '12.0'
2020
end

Sources/InAppSettingsKit/Controllers/IASKAppSettingsViewController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,8 +1300,8 @@ - (void)textViewDidChange:(IASKTextView *)textView {
13001300

13011301
- (void)cacheRowHeightForTextView:(IASKTextView *)textView animated:(BOOL)animated {
13021302
CGFloat maxHeight = self.tableView.bounds.size.height - self.tableView.contentInset.top - self.tableView.contentInset.bottom - 60;
1303-
CGFloat contentHeight = [textView sizeThatFits:CGSizeMake(textView.frame.size.width, 10000)].height + 16;
1304-
self.rowHeights[(id)textView.specifier.key] = @(MAX(44, MIN(maxHeight, contentHeight)));
1303+
CGFloat contentHeight = textView.contentHeight;
1304+
self.rowHeights[textView.specifier.key] = @(MAX(44, MIN(maxHeight, contentHeight)));
13051305
textView.scrollEnabled = contentHeight > maxHeight;
13061306

13071307
void (^actions)(void) = ^{

Sources/InAppSettingsKit/Views/IASKPSTextFieldSpecifierViewCell.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
2727
// TextField
2828
_textField = [[IASKTextField alloc] initWithFrame:CGRectMake(0, 0, 200, self.frame.size.height)];
2929
_textField.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin;
30-
_textField.font = [UIFont systemFontOfSize:kIASKLabelFontSize];
30+
_textField.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
3131
_textField.minimumFontSize = kIASKMinimumFontSize;
3232
[self.contentView addSubview:_textField];
3333

Sources/InAppSettingsKit/Views/IASKTextView.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ - (void)setFrame:(CGRect)frame {
8585
[self setNeedsDisplay];
8686
}
8787

88+
#pragma mark Getters
89+
90+
- (CGFloat)contentHeight {
91+
return [self sizeThatFits:CGSizeMake(self.frame.size.width, 10000)].height + self.superview.layoutMargins.top + self.superview.layoutMargins.bottom - 2 * self.textContainer.lineFragmentPadding;
92+
}
93+
8894
#pragma mark Private Methods
8995

9096
- (void)updateShouldDrawPlaceholder {

Sources/InAppSettingsKit/Views/IASKTextViewCell.m

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
3030
IASKTextView *textView = [[IASKTextView alloc] initWithFrame:CGRectZero];
3131
textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
3232
textView.scrollEnabled = NO;
33-
textView.font = [UIFont systemFontOfSize:17.0];
33+
textView.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
3434
textView.backgroundColor = [UIColor clearColor];
3535
[self.contentView addSubview:textView];
3636

@@ -42,14 +42,11 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
4242
- (void)layoutSubviews {
4343
[super layoutSubviews];
4444

45-
UIEdgeInsets padding = (UIEdgeInsets) { 0, kIASKPaddingLeft, 0, kIASKPaddingRight };
46-
if ([self respondsToSelector:@selector(layoutMargins)]) {
47-
padding = self.layoutMargins;
48-
padding.left -= 5;
49-
padding.right -= 5;
50-
padding.top -= 5;
51-
padding.bottom -= 5;
52-
}
45+
UIEdgeInsets padding = self.layoutMargins;
46+
padding.left -= self.textView.textContainer.lineFragmentPadding;
47+
padding.right -= self.textView.textContainer.lineFragmentPadding;
48+
padding.top -= self.textView.textContainer.lineFragmentPadding;
49+
padding.bottom -= self.textView.textContainer.lineFragmentPadding;
5350

5451
self.textView.frame = UIEdgeInsetsInsetRect(self.bounds, padding);
5552
}

Sources/InAppSettingsKit/include/IASKTextView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020

2121
@property (strong, nonatomic) IASKSpecifier *specifier;
2222
@property (strong, nonatomic) NSString *placeholder;
23+
@property (nonatomic, readonly) CGFloat contentHeight;
2324

2425
@end

0 commit comments

Comments
 (0)