From cd327a7f780427586b3acddb9620f06824942cc0 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 9 Aug 2022 14:35:28 -0500 Subject: [PATCH] added new attribute Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 10 ++++--- .../Attributes/LabelAttributeAttachment.swift | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 VDS/Components/Label/Attributes/LabelAttributeAttachment.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index c6251dea..79827a76 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -64,6 +64,7 @@ EAF7F11828A1475A00B287F5 /* RadioButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F11628A1475A00B287F5 /* RadioButtonModel.swift */; }; EAF7F12C28A1617600B287F5 /* SelectorBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F12B28A1617600B287F5 /* SelectorBase.swift */; }; EAF7F12F28A1619600B287F5 /* SelectorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F12E28A1619600B287F5 /* SelectorModel.swift */; }; + EAF7F13328A2A16500B287F5 /* LabelAttributeAttachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F13228A2A16500B287F5 /* LabelAttributeAttachment.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -139,6 +140,7 @@ EAF7F11628A1475A00B287F5 /* RadioButtonModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadioButtonModel.swift; sourceTree = ""; }; EAF7F12B28A1617600B287F5 /* SelectorBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectorBase.swift; sourceTree = ""; }; EAF7F12E28A1619600B287F5 /* SelectorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectorModel.swift; sourceTree = ""; }; + EAF7F13228A2A16500B287F5 /* LabelAttributeAttachment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeAttachment.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -269,9 +271,9 @@ EA3362442892F9130071C351 /* Labelable.swift */, EAF7F0BA289D80ED00B287F5 /* Modelable.swift */, EA3361BE288B2EA60071C351 /* ModelHandlerable.swift */, + EAF7F0A5289B0CE000B287F5 /* Resetable.swift */, EA3361C8289054C50071C351 /* Surfaceable.swift */, EA3361B7288B2AAA0071C351 /* ViewProtocol.swift */, - EAF7F0A5289B0CE000B287F5 /* Resetable.swift */, ); path = Protocols; sourceTree = ""; @@ -348,11 +350,12 @@ isa = PBXGroup; children = ( EAF7F0A3289B017C00B287F5 /* LabelAttributeModel.swift */, + EAF7F0B2289B1ADC00B287F5 /* LabelAttributeAction.swift */, + EAF7F13228A2A16500B287F5 /* LabelAttributeAttachment.swift */, + EAF7F0B0289B177F00B287F5 /* LabelAttributeColor.swift */, EAF7F0AA289B13FD00B287F5 /* LabelAttributeFont.swift */, EAF7F0AC289B142900B287F5 /* LabelAttributeStrikeThrough.swift */, EAF7F0AE289B144C00B287F5 /* LabelAttributeUnderline.swift */, - EAF7F0B0289B177F00B287F5 /* LabelAttributeColor.swift */, - EAF7F0B2289B1ADC00B287F5 /* LabelAttributeAction.swift */, ); path = Attributes; sourceTree = ""; @@ -510,6 +513,7 @@ EA33624728931B050071C351 /* Initable.swift in Sources */, EAF7F0A4289B017C00B287F5 /* LabelAttributeModel.swift in Sources */, EAF7F0B1289B177F00B287F5 /* LabelAttributeColor.swift in Sources */, + EAF7F13328A2A16500B287F5 /* LabelAttributeAttachment.swift in Sources */, EAF7F0B9289C139800B287F5 /* ColorConfiguration.swift in Sources */, EA3361BD288B2C760071C351 /* TypeAlias.swift in Sources */, EAF7F09A2899B17200B287F5 /* CATransaction.swift in Sources */, diff --git a/VDS/Components/Label/Attributes/LabelAttributeAttachment.swift b/VDS/Components/Label/Attributes/LabelAttributeAttachment.swift new file mode 100644 index 00000000..35008d14 --- /dev/null +++ b/VDS/Components/Label/Attributes/LabelAttributeAttachment.swift @@ -0,0 +1,26 @@ +// +// LabelAttributeAttachment.swift +// VDS +// +// Created by Matt Bruce on 8/9/22. +// + +import Foundation +import UIKit + +public protocol LabelAttributeAttachment: LabelAttributeModel { + func getAttachment() throws -> NSTextAttachment +} + +extension LabelAttributeAttachment { + public func setAttribute(on attributedString: NSMutableAttributedString) { + do { + let mutableString = NSMutableAttributedString() + let attachment = try getAttachment() + mutableString.append(NSAttributedString(attachment: attachment)) + attributedString.insert(mutableString, at: location) + } catch { + //TODO: Error Handling + } + } +}