Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attributed hint support added #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DerivedData/
*.perspectivev3
!default.perspectivev3
xcuserdata/
.DS_Store

## Other
*.moved-aside
Expand Down
6 changes: 3 additions & 3 deletions Example/RAGTextField/Images.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions Example/RAGTextField/Images.xcassets/info.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -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
}
}
26 changes: 24 additions & 2 deletions Example/RAGTextField/UnderlineViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}

Expand Down
15 changes: 15 additions & 0 deletions Sources/RAGTextField/Classes/RAGTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down