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.
Related
I have two UIButton's and I want to be able to have the user click one of the UIButton's and drag it over to another UIButton and have the title of the UIButton moved from the first UIButton to the second one. Is that possible? Thanks.
The title is an element of UIButton, so you can't use any predefined methods to do this. You'd have to create custom implementation where you added a draggable UILabel on touch, then set the button's title to match on release - or something like that.
I have created another answer that will at least get you on your way, it implements the press, the drag, and the up events for a button, where you are trying to recognize another button that you have dragged to!!!
Xcode iOS push down button and drag then up on a second button
Look at the answer provided by me!
I want to make a small area to present some information in the middle of a UIToolbar and was wondering what the best way to do this is.
I need to show some text and a graphic, both of which need to be updated (around every 3 seconds) as new information arrives. The graphic is similar to the iPhone signal strength indicator, so it can be either custom drawn or selected from one of 3 graphics (low, medium, high strength).
I'll probably use initWithCustomView: to create a UIBarButtonItem, although I would like the view to be clickable (to allow the user to change the information shown).
What's the best way to make that view? Can I use a NIB, or do I need to do custom drawing in the view? What's the best way to update the buttons? I'm assuming that I'll have to remake the toolbarItems array each time and set it when the information changes. Is there a cleaner way to do this? Thanks.
Using initWithCustomView: sounds like a good way to go. You can create your custom view any way you want: with a NIB, by drawing it, even using images. It can also have its own subviews. It can be any object that inherits from UIView. (So, if you wanted, you could even make it actionable by using a UIButton, a custom UIControl, or a custom UIView with a gesture recognizer attached.)
You shouldn't have to remake toolbarItems (or, for that matter, do anything with it after you've added all your button items) if you just keep a pointer to your custom view UIBarButtonItem. It could be an instance variable. Then, to update the custom view, you could access it as you would any other view. I've never actually tried this, but I can't see any problem with doing it.
You sound like you had it mostly figured out. Hope this is helpful.
I needed the same solution and was hoping for some code examples from you. So I ended up doing it all in IB and the steps are here as follows:
Create UItoolbar in IB with no Items. (A Bar Button Item will be added again once you add the UIView)
Add UIView as subview of UIToolbar
Add UILabels to subview of UIView that is already a subview of the UIToolbar.
Create IBOutlets from UIToolbar, UIView and each UILabel and then you can reference the labels in your app.
I did set the backgrounds to clearColor so the text appears on top of UIToolbar without any box or borders.
And the text updates dynamically which was the desired outcome.
Hope this helps someone as this has been eluding me for a while.
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.
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.
I'm trying to figure out a best way to implement the picture-editing capability shown in the native address book app on iPhone.
On the built-in address book, this is how the picture looks like before editing:
qkpic.com/2f7d4 http://qkpic.com/2f7d4
And after clicking edit, notice how "Edit" overlay is added and the image becomes clickable:
qkpic.com/fb2f4 http://qkpic.com/fb2f4
What would be the best way to implement something like this? Should I make the image a button from the beginning and have tapping disabled at first? If so, what steps are required to add an overlay/label to the image (in above example, gray border + the text "Edit" is added)
The easiest way is to use Interface Builder, create a container view, then add a UIImageView and UILabel as subviews to it. You would position and style the text and the image but set the UILabel to hidden. Make the whole container view respond to touches. It's easy to do since UIView is derived from UIResponder so all you have to do is override touchesEnded. Whenever you want to change the text label, just set the UILabel to hidden=NO.
There's more to it, however. Notice how the image has rounded corners? You'll want to override the UIImageView's drawRect method to implement a custom drawing routine to do that. There's lots of sample code around and it wasn't part of your original question so I'll stop here.