diff --git a/Core/Source/DTAttributedTextView.m b/Core/Source/DTAttributedTextView.m index 7636bf430..d772f85ee 100644 --- a/Core/Source/DTAttributedTextView.m +++ b/Core/Source/DTAttributedTextView.m @@ -57,12 +57,12 @@ - (void)dealloc - (void)layoutSubviews { - (void)[self attributedTextContentView]; + [super layoutSubviews]; + + self.attributedTextContentView.edgeInsets = self.contentInset; // layout custom subviews for visible area [_attributedTextContentView layoutSubviewsInRect:self.bounds]; - - [super layoutSubviews]; } - (void)awakeFromNib @@ -71,6 +71,11 @@ - (void)awakeFromNib [self _setup]; } +- (void)safeAreaInsetsDidChange +{ + [super safeAreaInsetsDidChange]; +} + // default - (void)_setup { @@ -287,14 +292,14 @@ - (void)setBackgroundColor:(DTColor *)newColor - (void)setContentInset:(UIEdgeInsets)contentInset { - if (!UIEdgeInsetsEqualToEdgeInsets(self.contentInset, contentInset)) + [super setContentInset:contentInset]; + + // height does not matter, that will be determined anyhow + CGRect contentFrame = CGRectMake(0, 0, self.frame.size.width - self.contentInset.left - self.contentInset.right, _attributedTextContentView.frame.size.height); + + if (CGRectEqualToRect(contentFrame, self.attributedTextContentView.frame)) { - [super setContentInset:contentInset]; - - // height does not matter, that will be determined anyhow - CGRect contentFrame = CGRectMake(0, 0, self.frame.size.width - self.contentInset.left - self.contentInset.right, _attributedTextContentView.frame.size.height); - - _attributedTextContentView.frame = contentFrame; + self.attributedTextContentView.frame = contentFrame; } } diff --git a/DTCoreText.xcodeproj/project.pbxproj b/DTCoreText.xcodeproj/project.pbxproj index b45154449..a209fb15b 100644 --- a/DTCoreText.xcodeproj/project.pbxproj +++ b/DTCoreText.xcodeproj/project.pbxproj @@ -891,9 +891,9 @@ A788C91014863E8700E1AFD9 /* DTAttributedTextCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTAttributedTextCell.h; sourceTree = ""; }; A788C91114863E8700E1AFD9 /* DTAttributedTextCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = DTAttributedTextCell.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; A788C91214863E8700E1AFD9 /* DTAttributedTextContentView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTAttributedTextContentView.h; sourceTree = ""; }; - A788C91314863E8700E1AFD9 /* DTAttributedTextContentView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = DTAttributedTextContentView.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + A788C91314863E8700E1AFD9 /* DTAttributedTextContentView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = DTAttributedTextContentView.m; sourceTree = ""; }; A788C91414863E8700E1AFD9 /* DTAttributedTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTAttributedTextView.h; sourceTree = ""; }; - A788C91514863E8700E1AFD9 /* DTAttributedTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = DTAttributedTextView.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + A788C91514863E8700E1AFD9 /* DTAttributedTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = DTAttributedTextView.m; sourceTree = ""; }; A788C91814863E8700E1AFD9 /* DTCoreTextFontCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTCoreTextFontCollection.h; sourceTree = ""; }; A788C91914863E8700E1AFD9 /* DTCoreTextFontCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DTCoreTextFontCollection.m; sourceTree = ""; }; A788C91A14863E8700E1AFD9 /* DTCoreTextFontDescriptor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTCoreTextFontDescriptor.h; sourceTree = ""; }; diff --git a/Demo/Resources/About.html b/Demo/Resources/About.html index ff7d5991d..af4f84950 100644 --- a/Demo/Resources/About.html +++ b/Demo/Resources/About.html @@ -1,6 +1,6 @@ -
+

DTCoreText consists of two portions:

  1. Parsing HTML and creating NSAttributedStrings
  2. @@ -11,4 +11,4 @@

    For example you could create a rich text about view like this here

    Note:You need to disable auto-layout on view controllers loading views from XIB because at present DTCoreText is not yet able to dynamically re-layout in auto-layout views.

    - \ No newline at end of file + diff --git a/Demo/Source/DemoAboutViewController.m b/Demo/Source/DemoAboutViewController.m index 60dede015..830486494 100644 --- a/Demo/Source/DemoAboutViewController.m +++ b/Demo/Source/DemoAboutViewController.m @@ -32,8 +32,17 @@ - (void)viewDidLoad NSString *path = [[NSBundle mainBundle] pathForResource:@"About" ofType:@"html"]; NSData *data = [NSData dataWithContentsOfFile:path]; - NSAttributedString *attributedString = [[NSAttributedString alloc] initWithHTMLData:data documentAttributes:NULL]; + NSDictionary *options; + + if (@available(iOS 13.0, *)) { + options = @{DTDefaultTextColor: [UIColor labelColor], DTUseiOS6Attributes: @(YES)}; + } else { + options = @{DTDefaultTextColor: [UIColor blackColor], DTUseiOS6Attributes: @(YES)}; + } + + NSAttributedString *attributedString = [[NSAttributedString alloc] initWithHTMLData:data options:options documentAttributes:NULL]; + self.attributedTextView.attributedString = attributedString; self.attributedTextView.contentInset = UIEdgeInsetsMake(10, 10, 10, 10); } diff --git a/Demo/Source/DemoAboutViewController.xib b/Demo/Source/DemoAboutViewController.xib index 3dea647a7..29c473bec 100644 --- a/Demo/Source/DemoAboutViewController.xib +++ b/Demo/Source/DemoAboutViewController.xib @@ -1,160 +1,30 @@ - - - 2048 - 14A388a - 6245 - 1343.14 - 755.00 - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 6238 - - - IBProxyObject - IBUIView - - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - PluginDependencyRecalculationVersion - - - - - IBFilesOwner - IBCocoaTouchFramework - - - IBFirstResponder - IBCocoaTouchFramework - - - - 274 - - - - 274 - {320, 548} - - _NS:9 - - 3 - MQA - - 2 - - - IBCocoaTouchFramework - - - {{0, 20}, {320, 548}} - - - 3 - MQA - - - - - IBUIScreenMetrics - IBCocoaTouchFramework - iPhone 4-inch - - YES - - - - - - {320, 568} - {568, 320} - - - 2 - - IBCocoaTouchFramework - - - - - - - view - - - - 3 - - - - attributedTextView - - - - 9 - - - - - - 0 - - - - - - 1 - - - - - - - - -1 - - - File's Owner - - - -2 - - - - - 4 - - - - - - - DemoAboutViewController - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - UIResponder - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - DTAttributedTextView - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - - - - 9 - - - 0 - IBCocoaTouchFramework - NO - - com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 - - - YES - 3 - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + +