I am receiving a server response as a sting that can contain some url or email address or phone number ie same string can have all three of them or one number and couple of url. Nothing is fixed.
I am using UITextView to show this sting on device. Now what I want is these url/email/phone number show up as hyperlink and on clicking these hyperlink user should be able to see a webpage if its a url, draft and send an email if its email address or call the number when clicked on number hyper link
Can anyone suggest me a way to do this. Or suggest any other data view to be used which can make things easy
Set the data detector types of your UITextView. There are a number of options:
UIDataDetectorTypePhoneNumber
UIDataDetectorTypeLink
UIDataDetectorTypeAddress
UIDataDetectorTypeCalendarEvent
UIDataDetectorTypeNone
UIDataDetectorTypeAll
So, in your case, you'd probably like to do:
self.myTextView.dataDetectorTypes = UIDataDetectorTypeAll;
Also note that the textview should not be editable when you use NSDataDetectorTypes.
Let textView be an object for UITextView, then set:
textView.editable = NO;
then only it can detect the links, phone numbers, address etc.
Add a UITextView in Interface Builder. No code needed. In Attributes Inspector, uncheck "Editable" and do check "Selectable". Do check "Phone Number" beside Data Detectors. Should work for other data types. DO be sure to edit the "Hint color" or else it may appear as no label is there (but you can still touch to launch). (Its a beautiful world, if you look at it the right way!)
You could use an UIButton, and change the title into the URL, email or phone number.
Create a custom UIButton with the corresponding format to make it look like a normal sentence (the edges and background of the button have the same color as the background of the view).
Format the text to make it look blue (and optionally underlined) like this so people know it's a hyperlink.
Related
Can we give click event for a particular word from a sentence. For example, let my label be
'myLabel.text = #"contact 123#gmail.com";'. I want to give click event for 123#gmail.com. Is it possible in IOS5/IOS6.
Thanks in advance.
In iOS5/6 there's a link detection system that will pick out links from a string, however it's not available in UILabel. If you can get away with using a UITextView then it'll work perfectly, if you desperately, definitely need a UILabel you'll need to work around it slightly and use something like TTTAttributedLabel or follow a similar approach and build your own UILabel replacement.
In my app I want the user to type names into a UITextField (or equivalent) and then when they press return, it will put that word(s) in a blue bubble that's usually associated with tags. The cursor then moves to the end where they can add more "tags".
This can be seen when adding contacts in the To, CC & BCC fields in the Mail app, and also when selecting contacts in the Messages app.
How is this done? Is it something that's provided in the UIKit or available somewhere else?
Many thanks,
Michael
Venmo just open sourced their token field.
https://github.com/venmo/VENTokenField.git
edited:
The equivalent control in desktop Cocoa is an NSTokenField, but there doesn't seem to be an equivalent for Cocoa Touch.
Since iOS 13 there exists UISearchTextField.
https://developer.apple.com/documentation/uikit/uisearchtextfield
You can see that component in action in the Photos App.
That should fit for many use cases. By removing the leftView you can also get rid of the search icon.
But be aware: You can‘t mix text and tokens at various positions.
From the docs:
Tokens always occur contiguously before any text in the search field.
Adding this here for reference:
Feel free to check out TaggerKit (a library I made), it's more or less what OP was talking about. You can basically add tags functionality to your app by just adding a view and a couple of properties.
I dont think you can do it with any built in functionality in the SDK, never seen such a feature. What you could do however is implement it yourself, have some custom blue button with some text over it, and when the user hits return you can have some code that takes the text and returns you the button that you need, shouldnt be too bad to implement
I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values varies. The problem is that the number pad does not contain a key for entering a decimal point.
When I lock my phone, the number pad that comes up to enter a passcode has a custom button to make an emergency call (as seen in the following screenshot):
Numberpad with custom button http://img25.imageshack.us/img25/6426/photoejg.jpg
Does anyone know how to create a number pad with a decimal point button or a custom button (like the emergency call button above)?
Thanks.
There's no Apple-approved way to edit the existing keyboard. If you want them to allow it, file a feature request.
That said, it just so happens that in most applications the keyboard (instance of UIKeyboard) is a separate UIWindow, and you can iterate over the windows in the application and start adding custom subviews that respond to the appropriate touch actions. Find it by iterating over [[UIApplication sharedApplication] windows] and checking to see if the description contains the string UIKeyboard. For more info on this method and some sample code, see this answer.
Another approach is to create your own custom view and build a keyboard from scratch. Be careful if you do this, though, as it requires a lot of manual work, not only in creating the keyboard and getting the touch behavior to match Apple's, but also in any control you add that would bring up the regular keyboard - you'll need to redirect things like becomeFirstResponder to show your own keyboard, rather than Apple's.
Edit: As ZaBlanc pointed out, newer versions of iOS have a way to do this with the inputView and inputAccessoryView properties. See the UIResponder class reference for details.
set UIKeyboardType to UIKeyboardTypeDecimalPad
Available in iOS 4.1 and later.
Create a UIViewController that contains a UIView with a bunch of buttons. Now your keyboard can have whatever you want on it.
In my app I want the user to type names into a UITextField (or equivalent) and then when they press return, it will put that word(s) in a blue bubble that's usually associated with tags. The cursor then moves to the end where they can add more "tags".
This can be seen when adding contacts in the To, CC & BCC fields in the Mail app, and also when selecting contacts in the Messages app.
How is this done? Is it something that's provided in the UIKit or available somewhere else?
Many thanks,
Michael
Venmo just open sourced their token field.
https://github.com/venmo/VENTokenField.git
edited:
The equivalent control in desktop Cocoa is an NSTokenField, but there doesn't seem to be an equivalent for Cocoa Touch.
Since iOS 13 there exists UISearchTextField.
https://developer.apple.com/documentation/uikit/uisearchtextfield
You can see that component in action in the Photos App.
That should fit for many use cases. By removing the leftView you can also get rid of the search icon.
But be aware: You can‘t mix text and tokens at various positions.
From the docs:
Tokens always occur contiguously before any text in the search field.
Adding this here for reference:
Feel free to check out TaggerKit (a library I made), it's more or less what OP was talking about. You can basically add tags functionality to your app by just adding a view and a couple of properties.
I dont think you can do it with any built in functionality in the SDK, never seen such a feature. What you could do however is implement it yourself, have some custom blue button with some text over it, and when the user hits return you can have some code that takes the text and returns you the button that you need, shouldnt be too bad to implement
can you give me a hint how to customize such a contact picker from e.g. Mail or Facebook App with the (+) Adding Contacts (or other data) to a UITextField for recipients .. each of the entries can be deleted then with the (x) ..
can you give me a hint where to start and what i should customize? thank you
Are you talking about something like this:
If so, you'll want to check out the TTPicketTextField UI component from the Three20 framework. It does exactly what you're after.