From 881364685258f768d3cf0423585fac627118c769 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 27 Jun 2019 15:29:33 -0400 Subject: [PATCH 1/2] Added exportIcon images. Added convenience function which adds the new images to attributed string. --- MVMCoreUI/Atoms/Views/Label.swift | 22 +++++++++++++++++ .../Media.xcassets/Contents.json | 6 +++++ .../externalLink.imageset/Contents.json | 23 ++++++++++++++++++ .../externalLink.imageset/exportBlack.png | Bin 0 -> 345 bytes .../externalLink.imageset/exportBlack@2x.png | Bin 0 -> 589 bytes .../externalLink.imageset/exportBlack@3x.png | Bin 0 -> 869 bytes 6 files changed, 51 insertions(+) create mode 100644 MVMCoreUI/SupportingFiles/Media.xcassets/Contents.json create mode 100644 MVMCoreUI/SupportingFiles/Media.xcassets/externalLink.imageset/Contents.json create mode 100644 MVMCoreUI/SupportingFiles/Media.xcassets/externalLink.imageset/exportBlack.png create mode 100644 MVMCoreUI/SupportingFiles/Media.xcassets/externalLink.imageset/exportBlack@2x.png create mode 100644 MVMCoreUI/SupportingFiles/Media.xcassets/externalLink.imageset/exportBlack@3x.png diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index a0733521..69e22119 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -340,6 +340,28 @@ public typealias ActionBlock = () -> Void standardFontSize = 0 } } + + /** + Appends an external link imcage to the end of the attributed string. + + - Attention: This method expects text to be set first. Otherwise, it will do nothing. + - Parameters: + - magnitude: Applied to Width and Height of image for congruency. + */ + public func addExternalLinkIcon(magnitude: Int = 12) { + + guard let attributedText = self.attributedText else { return } + + let fullString = NSMutableAttributedString(attributedString: attributedText) + + let imageAttachment = NSTextAttachment() + imageAttachment.image = MVMCoreUIUtility.imageNamed("externalLink") + imageAttachment.bounds = CGRect(x: 0, y: 0, width: magnitude, height: magnitude) + + fullString.append(NSAttributedString(string: " ")) + fullString.append(NSAttributedString(attachment: imageAttachment)) + self.attributedText = fullString + } } // MARK: - Atomization diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/Contents.json b/MVMCoreUI/SupportingFiles/Media.xcassets/Contents.json new file mode 100644 index 00000000..da4a164c --- /dev/null +++ b/MVMCoreUI/SupportingFiles/Media.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/externalLink.imageset/Contents.json b/MVMCoreUI/SupportingFiles/Media.xcassets/externalLink.imageset/Contents.json new file mode 100644 index 00000000..07a5a9f8 --- /dev/null +++ b/MVMCoreUI/SupportingFiles/Media.xcassets/externalLink.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "exportBlack.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "exportBlack@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "exportBlack@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/externalLink.imageset/exportBlack.png b/MVMCoreUI/SupportingFiles/Media.xcassets/externalLink.imageset/exportBlack.png new file mode 100644 index 0000000000000000000000000000000000000000..34f6d7e9c930cfd3b15aa1fd6be1e88c0e281a28 GIT binary patch literal 345 zcmV-f0jBPx$6G=otR5%gMk}*yLK@3GFhz__y1QnspDN^PFTp_38DAdpqr9z^BGE$T}%YPov z?wSm%DJZb?$6kMr*JC@SK{`x3FfKSG_gUq$XVa`u7`PWXB0WgIU=Oj*{8U|^!x^py z=}Hm3_fl4sjc-PqA;Ge-tqu#tTdY?n&sTlBLo z?S-ZACVU9Df(Z#~J$E`NHjG)I%RH#=e7oiRO`e=!;#=Y1-&Dnx*c!A}Px%2T4RhR9Fe^mpM|zFc3v&fC~_D2#6sfnRKe)8eD`ka1TNPa&kBX5EDVw(66np zl5LH=%o@0>+Pz7wuhwFFKC9CT^UN6K9>Zu}iOMP6i$vEiN@m5LcLHI&GkH(Sx$NeN)yQE z`(H+vWD1wYtT+S!m1gd9b9eV+QEJj_ZA%FhJHA8|%a=|N2TB!tV7J+fqsPE49-8sW zlAI^QvmKridz4BNkUa$1h8Y4a_~!pHhLi-!*^4_{uMZlPh`Wr=@5W5?!#EydM(#@~ z67_LJ7=05plW3YC^NX}^BHED*;WsE;fG zQU3^NYv)y&6Dc6P{vcj7eCY8S)F-H^ZPM~=t3m=oUhNT$dSePpNi0jcKeEA*&Ts2S z6&69JX{gX?>S*e_0K{(@U`Ej{_s|4rR0X;^O-nXasH*~9@$??z7Tq;uCV77L$$&l_-Z00000NkvXXu0mjf1aSuz literal 0 HcmV?d00001 diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/externalLink.imageset/exportBlack@3x.png b/MVMCoreUI/SupportingFiles/Media.xcassets/externalLink.imageset/exportBlack@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..15f13e3249cc453310cf2b87eed836add51186f8 GIT binary patch literal 869 zcmV-r1DgDaP)Px&A4x<(RA>e5SUYkQF%Y%E0faV*Q;vW+fD>~9LZ5+z09W}41SC{(4k8je;Q+u% zFjWMOTm}8c^R&HEOEc1FXLq*LRdQ=v-TnF_&5U(;VADTaypo<^YH1x)$6D;xo>0T$ z<%@@gI~Rks2z{sE8*_o&Uw^bLk2Yx;i#7;C3A#X!M1aYaTCk=cdp&d!V4ZO^)!qZv z*JREy=R6nyd2fN z|1E+SGH|GHxDHr*%*_WM7Df_4I;X;s)gRxkXvcd_m`gkS)+`j<7i-`OO;ZbwT${ue@I1DV{PhFgE3&M57Mk<9E@h7!cVd1 z0UwopDIS5yHwH!ka1gU|6ADWBmq(x7UmwVUaqE8*$#-RtGkp-{Prbnp;jd);l7Tlu zK**%V83Pb}f&0`|tJc;B05U-dU;9Y>T?5Pl(mf?RVvB9*)XZ$J5orU96edsH%9vNLh;}Puq%e8n{VgLO#OHYhNoq%Z;fvUO z_axnoTdei9Jq|5XYwTSLiZeKNDO21o?DK Date: Mon, 1 Jul 2019 14:23:44 -0400 Subject: [PATCH 2/2] link icon now scales in size with the text. --- MVMCoreUI/Atoms/Views/Label.swift | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index a524dbac..858e87d6 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -342,14 +342,11 @@ public typealias ActionBlock = () -> Void } } - /** - Appends an external link imcage to the end of the attributed string. - - - Attention: This method expects text to be set first. Otherwise, it will do nothing. - - Parameters: - - magnitude: Applied to Width and Height of image for congruency. - */ - public func addExternalLinkIcon(magnitude: Int = 12) { + + ///Appends an external link image to the end of the attributed string. + public func addExternalLinkIcon() { + + let size = round(font.pointSize * 0.8) guard let attributedText = self.attributedText else { return } @@ -357,7 +354,7 @@ public typealias ActionBlock = () -> Void let imageAttachment = NSTextAttachment() imageAttachment.image = MVMCoreUIUtility.imageNamed("externalLink") - imageAttachment.bounds = CGRect(x: 0, y: 0, width: magnitude, height: magnitude) + imageAttachment.bounds = CGRect(x: 0, y: 0, width: size, height: size) fullString.append(NSAttributedString(string: " ")) fullString.append(NSAttributedString(attachment: imageAttachment))