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 0000000..ed8306a Binary files /dev/null and b/Example/RAGTextField/Images.xcassets/info.imageset/128px-Infobox_info_icon.svg.png differ 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. ///