I'm building an app who has to obtain the address and some information of the user. I have one UIViewController with three UITextFields and I want to display the placeholders of each TextField like this picture.
Mockup Design of the UIViewController
How can I do that?
UITextField has built-in placeholder functionality. Just set the placeholder property of your text field:
textField.placeholder = "Casa 9 manzana E"
You can style the text field as needed. Take a look at the UITextField documentation for more details: https://developer.apple.com/reference/uikit/uitextfield
For multi-line, styled placeholders consider using attributedPlaceholder.
NSAttributedString allows to modify/style parts of the string differently.
You need To try This
Txtpwd.attributedPlaceholder = NSAttributedString(string: "Your Text",attributes: [ NSForegroundColorAttributeName=UIColor.darkGray])
Where TXTPwd in Outlet of Yore TextField
Related
I want to use below image keyboard with ".?123".
When we enable secure text for a password in UITextField it displays below the keyboard.
I want to display this keyboard without secure text in other UITextField.
Let me know if anybody has a solution for this.
You can set keyboard type from attribute inspector from story board..
You can also set it programatically like this
txtField.keyboardType = UIKeyboardType.default
So you can check it like this...
if txtField.isSecureTextEntry {
txtField.keyboardType = UIKeyboardType.default // whatever you want to set.
}
By default iOS Doesn't change the keyboard either the entry is secure or not.
Keyboard style is an independent property from data entry security.
You can change the keyboard type to .default, .numberPad, .phonePad, .email, .url by setting it to the property keyboardType of UITextField object.
yourTextField.keyboardType = .asciiCapable
You can also achieve above task from your Storyboard or Xib to know how to use in Xib and Storyboard please refer to Mahendra GP's answer above.
I am not able to clear the attributed text of UITextField when the Interface Button clear button is triggered.
I have tried _textfield.attributedText = nil; but it doesn't work. What happens next is that the UI freezes and I am not able to interact with the UI anymore.
Moreover, the attributedText is not removed from the UI.
Note:
I can't use text property of textfield because I have an icon and a string inside my attributedText. Hence, I must use this.
Any help is much appreciated.
Ronak
Why don't you try setting an empty attributed string:
let emptyAttributedString = NSMutableAttributedString()
textView.attributedText = emptyAttributedString
Perhaps you could place this within the IB Action hooked to your clear button?
So I'm trying to create a view where part of the entered text becomes a link to another UIView. I was searching a lot and found the ClickableSpan class that enabled to click on part of the text. It's like in Instagram where when a user types #username or #hashtag it creates a link to another view. I'm just wondering how to give an action to a portion of a text. The text can be in either UILabel or UITextView. Do I use AttributedString, or what?
You can do that for UITextView by using the dataDetectorTypes property.
Objective-C:
self.textView.dataDetectorTypes = UIDataDetectorTypeLink;
Swift
textview.dataDetectorTypes = .Link
I need create a UITextField, which can display both text and emoticon. Example, when I type : "abc :)", I will get "abc" text and smile-emoticon. So, how can I do that ?
My idea is create a UIView custom, every text is a UILabel, every emoticon is a UIImageView. But I see it is very complex. I want to find a simpler solution.
Thank for your support.
try pbrmojilable library
It may help you.
I want to create a custom input view, some of whose buttons insert "icons" into the selected UITextField, like the "RSS" or "Reader" icons which sometimes appear on the right hand side of the URL input field in Mobile Safari. I want the icons to be intermingled with the text and for all intents and purposes (like selection, cut and paste and deletion) behave like normal character glyphs.
Is there a name for these icons? Is there an API for creating them or do I have to build this entirely from scratch?
The leftView and rightView properties (instances of UIView) of the UITextField class are exactly for this purpose, and you can control their behaviour using the leftViewMode and rightViewMode properties. I suggest you to read the UITextField class reference for further details.
According to this question, what I want is an NSTokenField and there's not one available in stock iOS. However, there are some implementations on GitHub.