How can I put icons inside a UITextField? - ios

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.

Related

Create custom keyboard within app not external

How am I able to create a keyboard that is already enabled in the app, or is it just buttons put next to each other to make it seem like a keyboard. Like the image below
http://i.imgur.com/qIoxR0a.png
you can use to the UIButton element or UIView with TouchBegan. But don't keyboard extension because different controller.
You can use ETCustomKeyboard which is mostly like same as you need.
And the output of that is show into below image:
You can modify this as per your need.
And HERE is one more same like that.
Hope this will help.
Create the keyboard as an ordinary UIView, and make it the inputView for your text field. There is more information in Apple's Custom Views for Data Input page.

Is there something like UITextView for Apple Watch?

I need to display quite a bit of text and the only option I see is WKLabel. There are only about three screens worth of text so it isn't too big. How can this be accomplished?
If you use a WKInterfaceLabel set the lines property to '0' and set the height to Size To Fit Content in your storyboard.
You need to use WKLabel.
If you want your user to write something, use presentTextInputControllerWithSuggestions.
Text and labels from Apple Documentation
WatchKit provides a standard modal interface for retrieving text input from the user. When presented, the interface allows the user to enter text via dictation or to select from a standard set of phrases or emoji.

iOS Format Background

I am creating a simple quote app as a learning experience and need to format it to look better.
I am trying to make the background have a "white square" where the text is and make the text black. Just like the Twitter app has when you click on a tweet.
What is the best way to do this and what should I start with?
I know it is very simple, I'm only 15 and am trying to learn iOS. As you can see I have a server and have the app up and running, just want to format before I call it complete. Thanks! :)
-Henry
This will depend on how you created the label that displays your text, but you can do this very easily:
If you created your UI in a Storyboard / XIB file in XCode: assuming you dragged out a UILabel or UITextView, you can use the Attributes Inspector to set the text color and the background color (in the View section) of the element holding the text.
If you created the label (or text view) in code, you can set the textColor property and the backgroundColor properties programmatically.

detect urls in UILabel

I have a Tableview and tableview cell is customized to have a UILabel. The text in UILabel is having URLs. Is there a way to detect urls like how UITextView will enable detect URLs so that user interaction should be able to load the urls.
If you just want to identify the URLs, you can use NSDataDetector with the NSTextCheckingTypeLink checking type.
If you want to draw the URLs differently, and you are targeting iOS 6, you can use an NSAttributedString to turn the URLs blue or underline them or whatever. If you're targeting an older version of iOS, you will probably want to look for some free code on the Internet to draw styled text, like OHAttributedLabel.
If you want to actually make the URLs touch-sensitive, you can add a tap gesture recognizer to the label and try to figure out which part of the string was tapped (somewhat complicated), or look for some free code on the Internet that already does it for you (like OHAttributedLabel), or just put a UITextView in the table view cell instead of a label.
as Rob point out how can we achieved the same is awesome.
But, we can use a tact so can save with issue of ios version (possibly), just by using a UILabel and UIButton.
What we need to do is that, either from IB or story-board,just place a UILabel with string as URL(use this as title), say;
"www.myURL.com"
Now, just above it, place a UIButton(button with custom type), and just use "______"(underline) and set this button as overlap your UILabel and also the 'underline' must be beneath your label.
Now, just do in action of button whatever you required as you need on the click of URL and here also you can change the textColor, etc, properties; also load URL and navigate to UIWebView.

How do you have two fonts in one UITextView (Xcode)?

I'm trying to make two font styes in one UITextView, how do I do this?
From the class reference:
This class does not support multiple styles for text. The font, color,
and text alignment attributes you specify always apply to the entire
contents of the text view. To display more complex styling in your
application, you need to use a UIWebView object and render your
content using HTML.
You cannot have two on the same page because it is not supported. Just use a webview and an HTML file
You can know use this by using the attributedText property of UITextView. This is available under iOS 6
UITextView supports just a single font, but there's a different topic on something similar:
Can I use multiple font style in UITextView?
If the text you want to draw is simple, I'd suggest subclassing UITextView or UIView, overwriting the drawRect function and work with some extra variables of your own. This only works if you have a very predictable system to the fonts though.
Another option is using multiple labels, which would probably need an ever more predictable setup.

Resources