From 0ca4148596e98936ebbc29783feaaa59ef0716f3 Mon Sep 17 00:00:00 2001 From: "Abdullah Md. Zubair" Date: Sun, 8 Oct 2023 11:46:03 +0200 Subject: [PATCH] Attributed hint support added and DS_Store added to gitignore --- .gitignore | 1 + .../Images.xcassets/Contents.json | 6 ++-- .../128px-Infobox_info_icon.svg.png | Bin 0 -> 3134 bytes .../info.imageset/Contents.json | 21 ++++++++++++++ .../UnderlineViewController.swift | 26 ++++++++++++++++-- .../RAGTextField/Classes/RAGTextField.swift | 15 ++++++++++ 6 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 Example/RAGTextField/Images.xcassets/info.imageset/128px-Infobox_info_icon.svg.png create mode 100644 Example/RAGTextField/Images.xcassets/info.imageset/Contents.json diff --git a/.gitignore b/.gitignore index d534044..fa835c7 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ DerivedData/ *.perspectivev3 !default.perspectivev3 xcuserdata/ +.DS_Store ## Other *.moved-aside diff --git a/Example/RAGTextField/Images.xcassets/Contents.json b/Example/RAGTextField/Images.xcassets/Contents.json index da4a164..73c0059 100644 --- a/Example/RAGTextField/Images.xcassets/Contents.json +++ b/Example/RAGTextField/Images.xcassets/Contents.json @@ -1,6 +1,6 @@ { "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/Example/RAGTextField/Images.xcassets/info.imageset/128px-Infobox_info_icon.svg.png b/Example/RAGTextField/Images.xcassets/info.imageset/128px-Infobox_info_icon.svg.png new file mode 100644 index 0000000000000000000000000000000000000000..ed8306a303b099e9c6220f7a352c0f20adc295f2 GIT binary patch literal 3134 zcmZ`*cRUnu8~>fN_d4S!BztuByo`+0l};x+WZuPDmqc+Ar$eN&M|Ovdl8hu-$=)L( zS=n2eulLXQkN1z~`9ACWd7gis=kq+haow1O5zYtzU@^IDV0Mbc{|Y_zsm7{NbWefW zP4Ai>0OhevhmJI-zOd6}vugkZil5d!0bu_$L|g#i9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Qkum~692B;ltRarn~ zFO~)3-X0&OKx27 z8!R*xmvO@~fwtiB6Q59;=PGCh;up7JQZ@cM_0GiT;Un5CBVLf9w6Gr!ZC=C`HyqFB z9d_I-?WX3dy0ok;Q)!A{@B{AzSj_hm8bR)gpi|sZSHSROGAUH>ZYm!174>{859Zi| zPKi9*z*@h>gYRKetzQWD{k4ni2~1Zsw0`pZqv6bZIl{B*#bg5?KB_lMm=9L+WuXC0 zYzykGDK-N-_>~i*=`&O1(=K#H7d)1lAD{!I2BORW@ zM^Ea>um}jqadS~xSu@ISO5M++Y%>bw_26bb-Cze)NdNXOTINpcVy)|9Qllf z|5W-|pJ!`I17`IcL!6uX{j z<=~72jdu@McwgJ`7o+^c2#Gbr5t!SE3VCL3{|UKVNV?69Y!4^Hi6_B8I5*oAVPQ=a zfJrlZoTMJW(il}4?V)NEmQumhVef|DxcOMl zk?xy<{v-)?(*w^tkCe+T_J%Fr*knm)N?<-<4a^R@CsRk!BoPteD&2mT&w}~#Ni~!HdI_~yv(2X{mNRfwQV#l1hyAtU*^G~%=3t93sfNR*$a?<|w%63YI+GDa;oU6mdbLrP` z*&06?oiV7pCj)d4@Qv`rgC-Do%{0E;}dsCP7&p5$(6i^|8%`m5Chz)jbuRUGbm$_D7J# zsMsWx_N1C0OKGT7{m&}y;^`bb$^33ff!3eyOrB|cLoJb$e~3*ZJ7rBwpZosP2*g%*@u_R&zO7E zz7-caX*No9z#>|1LIg+`rDbfhHE)Ry1T5xUut9Yna^Jq&3H$G)&gahfZyRY6Z`tZG zS@%-wY&|zEWD6-)_}{IHPcLVz>x2JK5C}l~oDzVE;dO%&eTT>Y0f*bA A-~a#s literal 0 HcmV?d00001 diff --git a/Example/RAGTextField/Images.xcassets/info.imageset/Contents.json b/Example/RAGTextField/Images.xcassets/info.imageset/Contents.json new file mode 100644 index 0000000..651907e --- /dev/null +++ b/Example/RAGTextField/Images.xcassets/info.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "128px-Infobox_info_icon.svg.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Example/RAGTextField/UnderlineViewController.swift b/Example/RAGTextField/UnderlineViewController.swift index ef2ef96..1b720ad 100644 --- a/Example/RAGTextField/UnderlineViewController.swift +++ b/Example/RAGTextField/UnderlineViewController.swift @@ -47,7 +47,23 @@ final class UnderlineViewController: UIViewController, UITextFieldDelegate { bgView.layer.cornerRadius = 8.0 bgView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] } - + + let icon = UIImage(named: "info") + let iconHeight: CGFloat = 12 + let space = " " + + let attachment = NSTextAttachment() + let attachmentBounds = attachment.bounds + attachment.bounds = CGRect( + x: attachmentBounds.origin.x, + y: attachmentBounds.origin.y - 2, + width: iconHeight, + height: iconHeight) + + attachment.image = icon + let attachmentString = NSAttributedString(attachment: attachment) + + underlineModeTextField.textColor = .white underlineModeTextField.tintColor = .white underlineModeTextField.textBackgroundView = bgView @@ -60,7 +76,13 @@ final class UnderlineViewController: UIViewController, UITextFieldDelegate { underlineModeTextField.hintFont = UIFont.systemFont(ofSize: 11.0) underlineModeTextField.hintColor = ColorPalette.sky underlineModeTextField.hintOffset = 3.0 - underlineModeTextField.hint = "Natural mode supported as well" + + let hintAttributedString = NSMutableAttributedString() + hintAttributedString.append(attachmentString) + hintAttributedString.append(NSAttributedString(string: space)) + hintAttributedString.append(NSAttributedString(string: "Natural mode supported as well with hint icon")) + + underlineModeTextField.attributedHint = hintAttributedString } } diff --git a/Sources/RAGTextField/Classes/RAGTextField.swift b/Sources/RAGTextField/Classes/RAGTextField.swift index 8578ca5..616af00 100644 --- a/Sources/RAGTextField/Classes/RAGTextField.swift +++ b/Sources/RAGTextField/Classes/RAGTextField.swift @@ -144,6 +144,21 @@ open class RAGTextField: UITextField { return hintLabel.text } } + + /// The attributed text value of the hint. + /// + /// If `nil`, the hint label is removed from the layout. + @IBInspectable open var attributedHint: NSAttributedString? { + set { + hintLabel.attributedText = newValue + + updateHintVisibility() + invalidateIntrinsicContentSize() + } + get { + return hintLabel.attributedText + } + } /// The font used for the hint. ///