several uibuttons to subclass - iphone

I have several custom uibuttons on my view. I want to create a toggle button which when pressed, it will loop through all the UIButtons and enable a background image for them.
What I have done is to use an image as a background, then created clickable parts of it using blank custom buttons. I want this toggle function to then show the buttons.
My plan is to create a subclassed UIButton for the "hidden" buttons. When the toggle button is pressed, the code should then set the background image for each of these buttons to a "reddot.png". That stays on the screen until the toggle button is pressed again - this then disables each sub classed uibuttons background image.
What's the best way to do this?

I would advise you to not subclass UIButton for two reasons. First, UIButton is actually a class-cluster, which makes subclassing rather difficult. Secondly, I don't think it is needed in your case.
Simply create all the buttons as custom buttons. You can customize their appearance using methods like [button setHidden:] and [button setBackgroundImage:forState:]. The toggle button could then simply by linked to an IBAction, which would apply the appropriate customizations to the other buttons.

Related

How can I highlight the BarButton in navigation bar without tapping it?

Typically, the UIBarButtonItem will be highlighted when we tap it.
However, I intend to show the users that the action is automatically done for them when the view is loaded after 4 sec.
So I want to highlight the Button without tapping it.
How can I achieve that?
For a UIVIew object such as a UIButton, you can either use the following code Glow category on UIView that adds support for making views glow or use this example.
If you are using the first one, you can just call startGlowing and stopGlowing. When you call startGlowing, the view will start to pulse with a soft light, this effect is removed when stopGlowing is called. Check this.
For UIBarButtonItem, you might have to use the solution provided here.

UIBarButtonItem image/glyph in Standard UIButton

I'm trying to create a 'Refresh' button containing the standard UIBarButton refresh system glyph, which, when tapped, will animate a custom view, then fire another selector to call the intended refresh action.
I know I could do this with images and two inner views added to a custom view, but is there any way to do it with the standard glyphs from UIBarButtonItem? Are they available at all for UIButtons?
When I was creating my iOS application, I wasn't able to find a "refresh" button for the UIBarButtonItem. I had to take a Rounded Rect Button and place it in the top right hand corner and create a custom image to overlay onto it.
Edit: You can find it in IB. When you add the UIBarButtonItem, select it and then select the attributes inspector tab. Click the Identifier drop down and within that there is a selection to change the button to look like the system refresh button.

Subclass UIButton or inherit from UIControl?

I have an element that needs to behave like UIButton but it has several (3) text labels visible at once and multiple UIImages in the same bounding box. It's really a view with a bunch of different other UIViews and labels that needs to look and act like a button but with more custom placement of these elements than the standard UIButton.
Is it better to inherit from UIButton to accomplish this or is UIControl the one to inherit from?
When the element is tapped, I do want to mimic all of the highlighting effects (if it's UILabel, show the highlight text color, etc) as well.
As long as it doesn't matter which part of your button content gets tapped to activate it's functions you could compose a UIButton along with all the UILabel, UIImageViews you need.
You could easily inherit from UIView, place all of the above inside and place your transparent UIButton on top of everything to get the events you need (setting yourself as the target for that button and implementing some delegate to notify about selection).

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.

touch effect for Button in iphone

how can i just change the color,of a button when i set the focus on the button in iphone.
I mean to say , for example we have 5 buttons, and i am just setting the focus on each of the button. i want those buttons to be higlighted with different color.
but when press or touch up inside the utton, the navigation is made to the respective forms, that is set for that button.
you can write method, for example, let it be
- (void) changeButtonState:(UIButton*) buttonToChange;
then you can call it in your onBtnClk method for button you need. in that method you can change image for your button's UIControlStateNormal mode. and if I understand right, you can use toolbar or tabbar instead of buttons.
Guess you have already asked this issue differently here..
But have you checked the answer?? You can use any of those methods at your will!