More button in UILabel like in AppStore any app description - iphone

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.

Related

Add More Button in UiButton

I have a long string to show on UIButton. I want to show the first 2 lines and if the text is longer than that - add a More button that will pop up an alertview to show the full text. See the image
What is the best way to do that?
Add your more button and wire it up the standard way, but set it to hidden. Then determine the length of the string and see if it is bigger than your textview. If so, set the more button to visible. When the button is pressed resize the textview and add more lines.
I'm not around a Mac at the moment so don't take this answer as gospel.
I would think that if you added a UILabel as a subview of a UIButton and setup the label to only show two lines before truncating, you could then detect if the displayed text was different than the actual text you used when you created the label by using NSString's isEqualToString: method. If the strings are different you know the label is truncated and you should show the 'more' button. I found this code on StackOverflow that returns an NSString within an arbitrary NSRect.

How to apply the hyperlink for specific text in uitextfiuled or uilabel

i am developing one application.In that i want to use UILabel or UITextField to place the text.But i need to apply the hyperlink for some part of that text.I am searching on internet,no use of search.So please tell me how can i do that one for UILabel or UITextField.
Take two different labels, one for "Here" word and another for "is my application". Make userIneraction true for "Here" label. Apply gesture to that label and on touch of that label redirect user to appropriate link.

Hypertext in uilabel or uitextview

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.

Unable to Generate UITextField dynamically in place of UILabel?

I am trying to generate UITextField dynamically in place of UILabel.
Now i want to update that data.
I am displaying data in the UILabel from the database and there is an UIButton for editing.
When i click on that UIButton UITextField should be generated in place of UILabel and also data should be displayed in UITextField.
What you can do is to design a view with all textfield which works in two modes, first readonly (by setting userInteraction to false ) and second editing mode. This way you can avoid the use of labels. This will need only one edit button for all of the fields. if you still want to stick with your approach, you can hide the labels, use their frames to create textfields at their place and make them visible as long as you are working in edit mode. Don't forget to use
[self.view bringSubviewToFront:TEXT_FIELD];
While you add them to your view.
e
Managing the editing with the approach I mentioned earlier is mor easy and require less efforts. Hope it helps
you need to implement this textField in .h file, to get access to it when you finish aditing. Then, in your button callback:
textField = [[UITextField alloc] initWithFrame:[yourUILabel frame]];
[textField setText:yourUILabel.text];
[self.view addSubView:textField];
then, to replace it back:
[yourUILabel setText:textField.text];
[textField removeFromSuperView];
You can use the methods that others have described here but it sounds like you just want a UITextField that looks like a label and you want to control whether or not it's editable.
set enabled to YES / NO depending on whether you want the user to edit the UITextField
set the borderStyle of a UITextField (usually between UITextBorderStyleRoundedRect and UITextBorderStyleNone)
You can then toggle the enabled and borderStyle values as follows:
- on initial view: enabled: NO, border style: UITextBorderStyleNone
- on button tap: enabled: YES, border style: UITextBorderStyleRoundedRect
You don't have to mess with the view hierarchy and worry about frames, etc, this way.

How to set different width of elements [iPhone-dev]

Look this pic:
The usernames are UIButton. How can I put a UILabel (with the comment text) just after the UIButton (with the username) ?
The UIButton username's is dynamic. How can I do this?
That looks like a UITableView, if that's the case you should subclass UITableViewCell. If it isn't, I would
consider making it one
build a container class that (or make your subclassed UITableViewCell such that it) contains both a UIButton and a UILabel and dynamically position the text inside the label according to the size of the button (for instance, adding the right number of spaces to the beginning of the text).
You're going to have to use Core Text or web views to achieve this. There's really not a super easy way to do this. It's simple enough to place view next to each other based on their calculated sizes, but to have text wrap to multiple lines with embedded font style variations and attachments (i.e., images), you're going to have to read up on Core Text or use XHTML in web views.