UIImageView allows button beneath it to be touched - iphone

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

Related

Change view on button click

I am doing an iPhone project.
As part of it I want to know how to load a uiview to half portion of the screen when we click on a button.
You can use addSubview: from UIView Class
UIView *customView =[UIView alloc]initWithFrame:CGRectMake(10,100,200,200);//Give frame according to your view
customView.backgroundColor=[UIColor greenColor];
[Self.view addSubView: customView];

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

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.

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.

Standard UIButton with custom image

I'm trying to add a custom image on a standard UIButton. I know of the setBackgroundImage and setImage methods to do that. However, this will remove the 'standard' borders! Using UIButtonTypeCustom or UIButtonTypeRoundRect gives the same results...
Can this be so hard?
A normal button like those in the navigationbar - just a custom image instead of the titleLabel. Do I really have to draw the button itself in an image editor?
Yes you do have to draw a custom image.
Well you can add a subview of image to the UIButtonRoundRect. So just create a RoundRect button the usual way:
UIButton *button = [UIButton buttonWithType:UIButtonRoundRect];
then create an image view with your image and add it as subview to the button:
UIImageView *iv = [[UIImageView alloc] initWithImage:(UIImage *)image];
[button addSubivew:iv];
That should do the trick. Plus you can also set the position of that imageview by [iv setCenter:CGPointMake(x,y)];
Hope that helps.

what's the preferred visibility toggle for UIImage (like setHidden on UIButton)?

I'd like to control visibility on a simple UI element. If it was a button, I'd just call setHiden on it, but UIImage has no such method.
What's the preferred way of showing or hiding an image? Just making it a UIButton and not hooking it up to any methods seems wasteful.. is that really the right way to do it?
Shouldn't your image be in an image view?
UIImageView imageView = [[UIImageView alloc] initWithImage:myImage];
Then you can hide the image view with:
imageView.hidden = YES;
hidden is a property of UIView, so you can use it with UIImageViews.