Add More Button in UiButton - iphone

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.

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.

iPhone UIButton provide different inset values for highlighted state

I want my titleLabel text move a little down on button tap (i.e. I want to give different inset values for highlighted and default states).
I have custom button background images and the button goes down in highlighted state image but the text on it stands at the same place so it gives a bad effect and looks like the text is seperated from button.
Is there any way to solve this?
Thanks in advance
The easiest way to do this is to put your text on the button's background image.
If you can't do that for some reason you can try to add IBAction on Button down and adjust button.titleLabel.frame.

how to write text on selection indicator of uipickerview

how to write text on selection indicator of uipickerview
The simplest approach will be just to add UILabel with your text over the UIPickerView. You only need to find the right coordinates so text will be placed well.
If you want to display text on it try adding a UILabel as a subview to the view containing the picker. You just need to get the frame in the right spot - easy with IB, more trial and error through code. The set label to have a clear background. Just update the label value as needed.

iPhone Custom Text Field

I want to create a simple calculator application. I know a text field will display the calculations but is there any other way to display the results to the screen. Or increase the text field. I want a larger option.
Thanks
use UILabel instead of a UITextField.
If you need the textfield to show the keyboard you can move your textfield off screen and call [textfield becomesFirstRsponder]; from code.
But I would recommend a custom keyboard anyway.
For simple calculator application you can use UITextField or UIlabel for displaying your result. (Both are use for displaying output)
If you need to display static text with no editing features and no selection features, you should use a UILabel.
If you need selection or editing, use UITextView.

how to add text and images together

I'm developing a notebook based application. it consists of notes and images also.
I'm unable to find the best way of coding to add images and text together. it is also editable, so I'm getting confused whether to take scroll-view or text view. If I take scroll-view there is no editable option. if I take text view we can't change frames of the image .
Solved as follows. Taken Scrollview, in that managing size of the textview & inserting image with Specified size. Like textview,image,tetxview, image and goes on...
Thanks for all your support to solve the issue.
You can use a TableView. Put the image in a custom cell with the view as an ImageView.
Put a UITextField as the second cell for text note.
Alternatively, you can use a view swap method, where the text view is on the back of the image by clicking on an "Info" button to use the Flip transition and show the note. The facebook app does this now for "Comments" on photos.