How to add button to MBProgressHUD, relative to text label? - iphone

I want to add a custom cancel button to MBProgressHUD, and I want it to be just right of text label. But MBProgresHUD is drawn by overriding drawRect method, so, while I can add button as subview to HUD, i don't know how large text label will be so I can position my button properly.
How can this be achieved?

I'm not sure this is possible directly using MBProgressHUD. Not without rewriting much of it.
One option could be to just add your own button as a subview of the view you are adding the HUD to that would just close the HUD or cancel the action.
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 50, 50)]; // made up coords here
// set button stuff here
[self.view addSubview:button];
You will need to set the button actions, background or image (for look and feel), then add it to your view. Basically 2 views to achieve what you need. HUD and button. Probably a lot easier than rewriting MBProgressHUD to allow buttons.

Related

How to force a UIButton to always be on top

I have a UIButton and a UIView that animates, sliding down when the UIButton is pressed. The problem is that the UIView obscures the UIButton. I'd like the UIButton to always remain on top.
I tried this in the viewDidLoad:
[self.view bringSubviewToFront:categoryBtn];
doesn't work though.
thanks for any help
After Add any UIView or any other view on your this mainview , after that just add your this line for brings as a supeview for button
[self.view bringSubviewToFront:categoryBtn];
For Example on button action event you add any view then use code like bellow..
-(IBAction)yourButton_Clicked:(id)sender
{
///Add some code or view here and then after write this line here see bellow line
[self.view bringSubviewToFront:categoryBtn];
}
The other answer is will work, but this is exactly the kind of thing "insertSubview: belowSubview" was added for.
[self.view insertSubview:myNewView belowSubview:_categoryBtn];
This allows you to add the new view below the button on the view stack instead of adding it above the button and then rearranging the views.

UIImageView allows button beneath it to be touched

Am developing an iPhone App. When the user taps a button, displaying a semi-transparent UIImageView on a page (i.e. covering the whole page). Now, since the UIImageView is semi-transparent, the buttons beneath it are seen. Clicking on the buttons (though the UIImageView is on top of it) is causing the button-click to be processed ; but I want to stop this. When the UIImageView is on th e top, only touching UIImageView (which calls a method) should work ; touching anything beneath it shouldn't.
Suppose yourImageView is your UIImageView above your button, do this,
[yourImageView setUserInteractionEnabled:YES];
You have following alternatives :
First make sure that UIImageView is on top of button. Bring if front by using bringSubviewToFront
You can disable userInteraction of UIImageView.
If you have any action associated with UIImageView , then you can prefer UIButton over there instead of UIImageView and set your image as a background of UIButton , and add action you required to perform with this button.
your_semi_transparent_ImageView.userInteractionEnabled = YES;
You can add a UIView on the click of a button and then add UIImageview as a subview of view. Then decrease the alpha of uiview.
It would be better if you will add your semi-transparent imageView not to self.view but to your application's window. like this:
AppDelegate *delegate = (Appdelegate *)[[UIApplication sharedApplication] delegate];
[delegate.window addSubview:yourImageView];
To remove yourImageView just use
[yourImageView removeFromSuperView];
Hide and disable the buttons when the ImageView is shown:
[button setEnabled:NO]; // If you want the button not to respond
[button setHidden:YES]; // If you want the button not to be seen

Button borders in a grouped static UITableViewCell

I have placed a UIButton inside a static grouped cell and tried to make it fit to the cell border, but get this kind of double-lines:
I tried changing the separator style, but it didn't help. Is there a way to make the border-lines of the button invisible?
Thanks in advance.
From a design perspective, it might be better to add the button as a footer view for the table instead of embedded in a cell. Take a look at Calendar app on the iPhone. When you edit an existing event, they add a button at the bottom of the table for deleting the event. Theirs is a bit fancier than a simple rounded rect button, but that's trivial to do as well.
Embed your login button in a generic UIView and add it as such:
UIView *footerView = [[UIView alloc] initWithFrame:...];
UIButton *logInButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// do button set up here, including sizing and centering, and add to footer view
[footerView addSubview:logInButton];
self.tableView.tableFooterView = footerView;
[footerView release];
Change button type to custom and it will get rid of the Round Rectangle around the button.

IOS Custom UIButton

I currently work on a small application in which I have several UIButtons. Each of them has an UIImageView beneath it. At the moment, I associate each UIButton with each UIImageView (all are named via an IBOutlet - UIButton and UIImageView). When I press a button, the underlying image changes. I would like to know if it's possible (and how) to create a button which contains an underlying UIImage (not a UIButton image or background image), a sort of new object.
This image is slightly larger than the associated UIButton, like the apple calculator basic apps, and this image changes when I press the button.
I've tried several solutions (certainly incomplete) and I'm beginning to despair.
My current solution is functional but I do find it not particularly elegant.
UIButton has both image and backgroundImage as its properties.
To achieve what you are looking for, I would actually recommend you to stick to just a UIButton, and then using contentInset to position the image over the backgroundImage so it creates the effect I think you are looking for. This should be quite easy in interface builder...
you can make an invisible button and behind it make the image..
This will give you what you want but should be avoided at cost...
Stick to UIButton..
I believe even in calculator app they are only UIButtons and nothing else..
they have been coded to been momentary selected ..so that's why you see them kind of changing highlight for a small fraction and each button have been coded to perform specific function(+ - / equal .)
Update : i might be in doubt but if you asked for a button to have an image view inside it..
then here is the answer.
Make UIbutton. Make an ImageView and then call [theButton.view addSubview:ImageView];
Since both UIbutton and UIImage view inherit from UIView.. you can add as many subviews to them..that is inside them
If I understood your question correct then you may try the following:
UIButton *button = [UIButton alloc]init];
[button setImage:buttonImage forState:UIControlStateNormal]; when button not pressed
[button setImage:buttonImage forState:UIControlStateSelected]; when button tapped
[button release];

Add UIStuff in an UIView

I want to add my buttons in a UIView, like then I can hide or not them.
My button's code:
carte1J1=[UIButton buttonWithType:UIButtonTypeCustom];
carte1J1.tag=11;
carte1J1.frame=CGRectMake(60, 240, 50, 73.0);
[carte1J1 setImage:[UIImage imageNamed:[NSString stringWithFormat:#"%#",imagecarte1] ] forState:UIControlStateNormal] ;
[carte1J1 addTarget:self action:#selector (clicCarte1J1) forControlEvents:UIControlEventTouchUpInside];
[self.view insertSubview:carte1J1 atIndex:1];
My view is viewJoueur1, I try to add my button in the view like this.
[viewJoueur1 addSubview:carte1J1];
And to test I try to hide viewJoueur1:
viewJoueur1.hidden=YES;
But the button is still visible and I don't understand why
In the first section of code that you listed, you have:
[self.view insertSubview:carte1J1 atIndex:1];
In the second section, you have:
[viewJoueur1 addSubview:carte1J1];
So, you've added cartelJ1 to two views if I'm understanding correctly.
Then, you hide one of those two views, but self.view is still visible, and it contains cartelJ1, so cartelJ1 is still visible.
Please correct me if I'm misunderstanding your code...
You’re right, that isn’t the documented behavior:
Hiding a view with subviews has the
effect of hiding those subviews and
any view descendants they might have.
You’re adding carte1J1 as a subview of viewJoueur1; is viewJoueur1 a plain UIView or a custom subclass? If it’s a subclass, have you overridden -setHidden:?
If it’s a standard UIView, then this behavior is not as documented and you should report it as a bug.
One thing that I notice is that when you create the button, you add it as a subview of self.view, then later add it as a subview of viewJoueur1. Views can only be a subview of one view at a time, so the first one is redundant.