Hypertext in uilabel or uitextview - iphone

Is there any way to make a hypertext in the text for UILabel or UITextView?

It is easy to do with UITextview. You can set the datadetectortype for UITextview.
textView.dataDetectorTypes = UIDataDetectorTypeLink;

You can set any action on lable or textview, don't forget to check "User Interaction Enabled", make it transparent, and open a link on it!

As of now I tried for UILabel hyper link by providing gesture on label and never tried for UITextView.But more convenient way is providing a button with an action method that is easy way.some more details may useful for your work hyperlink providing from the NSString.

Related

More button in UILabel like in AppStore any app description

I have a description of myObject and i show it in UILabel. I want to add 'More' button to my UILabel if a description is too long. On Github i have found TTTAttributedLabel which allows to use hyperlinks. The question is, is there some special features in UILabel or UITextView to resolve my issue or i have to use TTTAttributedLabel?
The best option is certainly to use TTTAttributedLabel.
UILabel and UITextView are designed simply for showing static text. There is no method for adding tappable elements.
As an alternative, before I leaned of TTTAttributedLabel I simply placed a UIButton with a custom style over my UILabel. The button was invisible but still responded to taps. This works best for static text though, as the button needs to be placed correctly on the interface to cover the correct part of the text.
With TTTAtributtedLabel is pretty easy to add a "MORE" text at the end.
You have truncationTokenString and truncationTokenStringAttributes. Super easy!
Example:
[label setTruncationTokenString:#"... MORE"];
https://github.com/mattt/TTTAttributedLabel
Documentation: http://cocoadocs.org/docsets/TTTAttributedLabel/1.8.0/Classes/TTTAttributedLabel.html#//api/name/truncationTokenString
In my case I don't need anything more because I just change the numberOfLines when the cell is selected to make it grow.
You can try the 3rd library ExpandableLable written by Swift.
Set the custom class of your UILabel to ExpandableLabel and set the desired number of lines and collapsed text:
expandableLabel.numberOfLines = 5
expandableLabel.collapsedAttributedLink = NSAttributedString(string: "more")
expandableLabel.ellipsis = NSAttributedString(string: "...")
// update label expand or collapse state
expandableLabel.collapsed = true
You may need set a delegate to get notified in case the link has been touched.

How to add a custom clear button in UITextField?

I want to resize the default clear button of UITextField. After I googled a lot, I came to know there is no way to modify it.
So I decided to go with Custom option ie, by adding UIButton to text field.I found some code from S.O, but nothing works for me. These are the links which I referred.
Custom UITextField clear button
Custom clear button for UITextField
Custom clear button in UISearchBar text field
So please suggest some solution which behaves exactly as default clear button of UITextField
Any help will be appreciated.
Thanks in advance.
In addition to the jake9115 response, you can emulate the clearbutton behavior by using the UITextFieldDelegate callbacks.
You can try in this way:
Show the button when -textFieldDidBeginEditing: is called
Hide the button when -textFieldDidEndEditing: is called
Hide the button if in -(BOOL)textFieldShouldClear:(UITextField*)textField the length of the textField's text is 0.
Why not just make a button that sets the TextView's value to ""?
- (IBAction)button:(id)sender {
_myTextView.text = "";
}

Add image to UiTextView and post it

I want to add smily image in UITextview and also some text and then when i press send button all data from Textview i want to post.
you could use a container view that will include your UIImageView for showing the image and UITextField for allowing to enter the text and UIButton button to grab the text.
The below is the approach ... which you can use.
[myContainerView addSubview:myImageView];
[myContainerView addSubview:myTextView];
[self.view addSubview:myContainerView];
Did you Try out this one when you EGOTextView rather than the UITextView... i have tried to search a lot for your answer but need some more time to get it done. in the mean while try that out.

Link a UILabel and a UIButton in IB

During a time in my app - I make a button a button not enabled
myButton.enabled = NO;
The problem is that I've made my button in IB with an image, and just a UILabel overtop of it.
The label does not grey out when the buttons does.
In IB - is there a way to link the label to the button?
This is not possible without you doing the linking action yourself, as #Eiko rightly pointed out.
It sounds like you need to make your image the background-image of the button, so you can have your label as the button text, like it is intended to be used. Then you can specify colors, fonts & images for all 4 possible states.
If you decide to invent the wheel yourself, by keeping button and label as separate objects, you will have to invent everything around it as well.
You can add another outlet in your code, i.e. IBOutlet UILabel *yourLabel;
Then link this outlet to your label, same procedure as linking the button.

Implementing "add photo" button similar to the iPhone contacts app

I was curious if anybody knew the process to create an "add photo" image tile similar to that in the iPhone contacts app. It seems to be on the same level as a UITableViewCell which is shortened (if this is the way it is done).
I've read a suggestion dealing with Headers or custom UITableViewCells but nothing definitive on how it was done. Any illustrative code snippets would be most welcome.
Thank you for any replies.
It's just a UIButton added to a UITableViewCell. You can simply use the addSubview method of the UITableViewCell to add a button to the cell.
It is a header. Most of the functionality is in the 'HeaderFooter' example from the apple developer site. In that example they use a UIImageView for the photo area, but you can implement it with a UIButton instead. If you do this, just set the text to 'Add Photo' when desired, with a blue bold font of about size 12. If you want to leave it as an imageView, you'll have to put a subview with the text on top of it.
The name part can easily be recreated with a UIButton with a PNG image of a detail disclosure icon set as the button Image. It really looks like a small UITabelViewCell.
If you really want you can use a tiny UITableViewCell instead of the PNG for to render the detail disclosure icon, but that's a heavier, more kludgy solution.