iPhone UIButton provide different inset values for highlighted state - iphone

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.

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 make a such animation of UItextView or TTTextView as shown in picture

an App Shopper implement
As shown in picture:
there is a table item or a button "Read More..."
when click this button, the button animates to this piece of words' end to show all words up. As shown in picture 2
Is it a UITextView?
The "Button" is a UIButton or a Table Item?
How to implement this animation?
I did something similar by simply having UILabels and UITextViews lined up vertically. For the button I use a transparent UIButton of type UIButtonTypeCustom. Then I change the frame & text of the labels / textviews (the one with the text, and the ones below it) in an animation block.
There is also a way to do this in a table view. There is an Apple sample code project with section headings that you can click to expand. But the section is still visible, so perhaps this is not the right approach for you.

How to have a bordered UIBarButton Item with both Image and Text - Like in Mail

In the Mail app on iPhone, when the user taps Edit, the toolbar shows two buttons, Delete and Move. These buttons have both image and text while appearing as bordered.
I tried to recreate this effect, but I have not really succeeded. Here's what I've tried:
The obvious way of setting the image and text properties. This results in some weird button with the image on top and the text below it.
Initialize the UIBarButtonButton with a custom view set to an instance of UIButton (described here). This button can then not be set to be bordered, instead it appears as a flat view (without shadows either).
I could obviously create a button and then add an UIImageView as a subview to the toolbar, but then I have to care about device rotation and some other stuff I would like to avoid. Also, I think Apple doesn't do it this way; when you select an email in Mail while in editing mode, the button label is updated with (-number-), which moves the image slightly to the left. It looks like the text and the image belong together.
So I wonder whether anybody did something like this?
Most likely these are UIButtons with stretchable image backgrounds. That's how I would do it.

UIButton states

I am making multiple custom buttons that look much like this:
It is a simple button with either the green or gray in the "indicator view". What I need some explanation for is: In interfacebuilder there are four states a button can have; Normal, Highlighted, Selected and Disabled. When I provide images for everything except disabled I thought that normal would be when no touches were made on the button, highlighted is while you hold your finger on it and selected would be when after you release finger.
However I do not think thats right now. I use the touch-up-inside event. Is it correct that I need to set the selected/highlighted etc property on the button?
Thank you for your time.
You might want to set to selected and not highlighted.
Highlight is darkening the button for a fraction when touching the UIButton. UIButton can modify your image automaticaly so usually you don't need to provide a highlight image.
Disabled is when it is disabled.
Selected is when it is selected. You can invert the select flag on touch up inside event to make a state button.
[button setSelected:![button isSelected]];
Yes, you need to respond to the touch up inside by setting the button to highlighted.
Btw, it's "disabled" not deselected, but it doesn't sound like you need that state.

Custom UIToolBar from Images

I need to create a UIToolbar object that uses an image for the background. Most of the buttons are images as well, and rectangular. One button, however, is round and overlaps the toolbar like the Start button on the Windows task bar. See below.
I know that I will need to subclass the UIToolbar to paint the image for the toolbar -- I think. If so, does anyone have example code showing how to do this?
Furthermore, does anyone have any ideas on how to implement the larger round button? I'm thinking of another custom subclass for this, but not sure if there might be an easier way.
I can have the art guys chop the image anyway needed, which I'm sure the round button will need to be chopped some how.
Any ideas or sample code?
alt text http://iphone.sophtware.com/toolbar.png
Maybe you'll find some inspiration at this tutorial : Recreating The Raised Center Tab Bar Button of Instagram, DailyBooth & Path
For the color, you can experiment with the tintColor property.
As for the rest, UIToolbar is not designed for this. You will need a custom component (probably based on UIView).
I think it is possible but hard.
Override the drawRect method of the toolbar to draw the whole image. Then add left and right buttons.
For the round button you can add one invisible button on the bottom middle of the View and another invisible button in the middle of toolbar. Of course, you can try to use the views instead of the buttons and track the user interaction manually.