Dismiss custom alert view iOS - ios

I'm setting up a subclass of UIView to roll my own UIAlertView style view. I've got everything set up properly with displaying the view, but I'm at a bit of a loss as to how to dismiss the view properly. Specifically, when a user taps on the button in the view, it needs to animate out of the main view. This is the code for the view itself:
+ (void)showCustomAlertWithTitle:(NSString *)titleString andMessage:(NSString *)messageString inView:(UIView *)view andButton1Title: (NSString *)button1Title andButton2Title: (NSString *)button2Title
{
UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
CGRect windowFrame = window.frame;
[view setAlpha:0.5f];
UIColor *buttonColor = [UIColor colorWithRed:0/255.0f green:130/255.0f blue:216/255.0f alpha:1];
UIColor *titleColor = [UIColor colorWithRed:0/255.0f green:153/255.0f blue:102/255.0f alpha:1];
// Shade
UILabel *shadeWindow = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, windowFrame.size.width, windowFrame.size.height)];
shadeWindow.backgroundColor = [UIColor blackColor];
shadeWindow.alpha = 0.50f;
// Define size and origin of alert box
float alertBoxHeight = 225;
float alertBoxWidth = 200;
float alertBoxXorigin = windowFrame.size.width / 2 - (alertBoxWidth / 2);
float alertBoxYorigin = windowFrame.size.height / 2 - (alertBoxHeight / 2);
// Initialize background
UIView *alertBackground = [[UIView alloc] initWithFrame:CGRectMake(alertBoxXorigin, alertBoxYorigin, alertBoxWidth, alertBoxHeight)];
alertBackground.layer.cornerRadius = 5.0f;
[alertBackground.layer setMasksToBounds:YES];
alertBackground.layer.backgroundColor = [UIColor whiteColor].CGColor;
// Title Label
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, alertBoxWidth, 40)];
titleLabel.text = titleString;
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.textColor = titleColor;
titleLabel.layer.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.05f].CGColor;
[titleLabel setFont:[UIFont fontWithName:#"AvenirNext-Bold" size:20.0]];
// Title Divider
UILabel *titleDivider = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, alertBoxWidth, 1.0)];
titleDivider.backgroundColor = [UIColor grayColor];
titleDivider.alpha = 0.5f;
// Alert Message Text
UITextView *alertMessage = [[UITextView alloc] initWithFrame:CGRectMake(0, 40, alertBoxWidth, alertBoxHeight - 90)];
alertMessage.text = messageString;
alertMessage.layer.backgroundColor = [UIColor whiteColor].CGColor;
[alertMessage setFont:[UIFont fontWithName:#"Avenir" size:15.0]];
alertMessage.textAlignment = NSTextAlignmentCenter;
alertMessage.textColor = [UIColor grayColor];
[alertMessage setEditable:NO];
// Button 1
UIButton *button1 = [[UIButton alloc] init];
UIButton *button2 = [[UIButton alloc] init];
[button1 addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
if (button2Title == nil)
{
button1.frame = CGRectMake(10, alertBoxHeight - 50, alertBoxWidth - 20, 40);
}
else
{
button1.frame = CGRectMake(10, alertBoxHeight - 50, (alertBoxWidth / 2) - 20, 40);
button2.frame = CGRectMake(alertBoxWidth / 2 + 10, alertBoxHeight - 50, (alertBoxWidth / 2) - 20, 40);
}
button1.layer.backgroundColor = buttonColor.CGColor;
[button1 setTitle:button1Title forState:UIControlStateNormal];
[button1.titleLabel setFont:[UIFont fontWithName:#"AvenirNext-Bold" size:15.0f]];
button1.layer.cornerRadius = 2.5f;
[button1.layer setMasksToBounds:YES];
// Button 2
button2.layer.backgroundColor = buttonColor.CGColor;
[button2 setTitle:button2Title forState:UIControlStateNormal];
[button2.titleLabel setFont:[UIFont fontWithName:#"AvenirNext-Bold" size:15.0f]];
button2.layer.cornerRadius = 2.5f;
[button2.layer setMasksToBounds:YES];
// Bounce Implementation
alertBackground.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^
{
alertBackground.transform = CGAffineTransformIdentity;
}
completion:^(BOOL finished)
{
// do something once the animation finishes, put it here
}];
[window addSubview:view];
[window addSubview:alertBackground];
[view addSubview:shadeWindow];
[view bringSubviewToFront:alertBackground];
[alertBackground addSubview:button1];
[alertBackground addSubview:titleLabel];
[alertBackground addSubview:titleDivider];
[alertBackground addSubview:alertMessage];
[alertBackground addSubview:button2];
[alertBackground bringSubviewToFront:titleDivider];
/* [[[customAlerts sharedInstance] subViewArray] addObject:alertBackground];
[[[customAlerts sharedInstance] subViewArray] addObject:view];
[[[customAlerts sharedInstance] subViewArray] addObject:window];*/
}
When button1 is tapped, for instance, I need to have it animate the view out of the superView and remove it from the stack. I'm not sure how to handle this. Does anyone have any ideas?

To permanently remove a view, I generally use the UIView instance method removeFromSuperview. followed by a line setting the relevant variable to nil:
[myAlertView removeFromSuperview];
myAlertView = nil;
In your case then, I think you need to move the view off the screen by animating the its bounds property, then use the above couple of lines to remove any references to it.

Just found the answer here:
Dismiss view controller from #selector without creating seperate method
Had to download some custom classes but it worked:
[button1 addEventHandler:^(id sender, UIEvent *event)
{
[UIView animateWithDuration:0.25f animations:^{
[alertBackground setAlpha:0.0f];
[shadeWindow setAlpha:0.0f];
[window setAlpha:0.0f];
}];
} forControlEvent:UIControlEventTouchUpInside];
Custom classes can be found here:
https://github.com/ZeR0-Wu/JTTargetActionBlock

Related

how to remove subview from class method in ios?

I have an app.In this app so many class methods used.I want to know is it possible to remove subview from class mehtod?
+(void)addPregressIndicator:(NSString *)strText view:(UIView *)ShowView
{
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
UIView *busyView = [[UIView alloc] initWithFrame:appFrame];
busyView.backgroundColor = [UIColor clearColor];
busyView.opaque = YES;
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 95, 95)];
container.layer.borderWidth = 5;
container.layer.cornerRadius = 10;
container.layer.borderColor = [UIColor whiteColor].CGColor;
[container setBackgroundColor:[UIColor blackColor]];
UIActivityIndicatorView *av = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
av.center = CGPointMake(container.center.x, 34);
av.hidesWhenStopped = NO;
[av startAnimating];
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 95, 30)];
lbl.text = strText;
lbl.textAlignment = NSTextAlignmentCenter;
lbl.center = CGPointMake(container.center.x, 70);
lbl.textColor = [UIColor whiteColor];
lbl.backgroundColor = [UIColor clearColor];
[container addSubview:av];
[container addSubview:lbl];
container.center = busyView.center;
[busyView addSubview:container];
[ShowView addSubview:busyView];
}
+(void)removePregressIndicator:(UIView *)hideView;
{
// i want remove busyview that subview in viewcontroller.
}
Please help me to remove subivew.
You can set a unique tag for the busyView like this busyView.tag = your unique tag;
And then you can remove the view with this code
+(void)removePregressIndicator:(UIView *)hideView;
{
UIView *busyView = [hideView viewWithTag:your unique tag];
if (busyView){
[busyView removeFromSuperview];
}
}
You should make sure that the busyView tag is unique for all the subviews of hideView.
Assigne tag to a each view and access the view with tag and put it
+(void)removePregressIndicator:(UIView *)hideView;
{
UIView *viewToRemove = [self.view viewWithTag:assigne_tag];
[viewToRemove removeFromSuperview];
}
+ (void)removePregressIndicator:(UIView *)hideView;
{
UIView *progView=[self.view viewWithTag:YourTag];
[progView removeFromSuperview];
}

Displaying a custom line over view

Hi I want to show a line in over view like given image.
But when i am doing this i m getting line in complete view .
My code-
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(2,30, _MovetoSearch.frame.size.width, 1)];
lineView.backgroundColor = [UIColor whiteColor];
[_MovetoSearch addSubview:lineView];
How to make line like above image ?
When you set child view frame that time always set it using parent view frame so if in future you can change parent frame then no need to change child frame its automatically change as per parent view like I write as follow.
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(_MovetoSearch.frame.origin.x+2,_MovetoSearch.frame.size.height-5, _MovetoSearch.frame.size.width-30, 1)];
lineView.backgroundColor = [UIColor whiteColor];
[_MovetoSearch addSubview:lineView];
I assume your searchBtn is having similar kind of code
UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[searchBtn setFrame:CGRectMake(_MovetoSearch.frame.size.width-32, 0, 32, 32)];
[searchBtn setImage:[UIImage imageNamed:#"search.png"] forState:UIControlStateNormal];
[searchBtn setImage:[UIImage imageNamed:#"search.png"] forState:UIControlStateHighlighted];
[searchBtn addTarget:self action:#selector(searchBtnPressed) forControlEvents:UIControlEventTouchUpInside];
For your UITextField should be
CGFloat fieldHeight = searchBtn.frame.size.height-2;
CGFloat fieldWidth = _MovetoSearch.frame.size.width - (searchBtn.frame.size.width + 4);
UITextField *textfield = [[UITextField alloc] initWithFrame:CGRectMake(2, 0, fieldWidth, fieldHeight)];
[textfield setBackgroundColor:[UIColor clearColor]];
[textfield setBorderStyle:UITextBorderStyleNone];
[textfield setNeedsDisplay];
[_MovetoSearch addSubview:textfield];
for line view
CGFloat fieldHeight = searchBtn.frame.size.height-2;
CGFloat fieldWidth = _MovetoSearch.frame.size.width - (searchBtn.frame.size.width + 4);
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(2, fieldHeight+1, fieldWidth, 1)];
lineView.backgroundColor = [UIColor whiteColor];
[_MovetoSearch addSubview:lineView];
Hope it will work for you
I would suggest to use layer for such task and not overuse UIView.
CALayer * lineLayer = [CALayer alloc]init];
[lineLayer setFrame:CGRectMake(x,y,width,1)];
[lineLayer setBackgroundColor:[UIColor whiteColor].CGColor];
[self.view.layer addSublayer:lineLayer];

How to switch View Controllers in iOS?

I've looked all over Google & Stack Overflow, but I haven't found one clear answer. How do I switch to the TOCViewController after tapping the UIButton? I'm currently using "presentViewController" but it just freezes on tapping the button. Thanks in advance for any help.
#import "SplashLoginViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "TOCViewController.h"
#interface SplashLoginViewController ()
#end
#implementation SplashLoginViewController
- (void) displayTOC {
TOCViewController *toc = [[TOCViewController alloc] init];
[self presentViewController:toc animated:YES completion:nil];
}
- (void)initializeSplashView
{
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height)];
backgroundView.backgroundColor = [UIColor colorWithRed:52.0/255.0 green:170.0/255.0 blue:220.0/255.0 alpha:1.0];
backgroundView.tag = 1;
backgroundView.layer.zPosition = 99.0f;
[self.view addSubview:backgroundView];
UILabel *codeworksLabelView = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width, self.view.bounds.size.height / 2.0 - 25.0, self.view.bounds.size.width, 50.0)];
codeworksLabelView.text = #"Codeworks";
codeworksLabelView.textAlignment = NSTextAlignmentCenter;
codeworksLabelView.textColor = [UIColor whiteColor];
codeworksLabelView.font = [UIFont fontWithName:#"Montserrat" size:30.0];
codeworksLabelView.tag = 2;
codeworksLabelView.layer.zPosition = 100.0f;
[self.view addSubview:codeworksLabelView];
}
- (void)initializeLoginView
{
CGRect loginFrame = CGRectMake(50.0, 100.0, self.view.bounds.size.width - 100.0, 30.0);
CGRect passwordFrame = CGRectMake(50.0, 180.0, self.view.bounds.size.width - 100.0, 30.0);
UITextField *usernameInput = [[UITextField alloc] init];
usernameInput.frame = loginFrame;
usernameInput.placeholder = #"Username";
usernameInput.font = [UIFont fontWithName:#"Montserrat" size:15.0];
usernameInput.returnKeyType = UIReturnKeyNext;
usernameInput.tag = 3;
usernameInput.autocorrectionType = UITextAutocorrectionTypeNo;
UITextField *passwordInput = [[UITextField alloc] init];
passwordInput.frame = passwordFrame;
passwordInput.placeholder = #"Password";
passwordInput.font = [UIFont fontWithName:#"Montserrat" size:15.0];
passwordInput.returnKeyType = UIReturnKeyDone;
passwordInput.tag = 4;
passwordInput.secureTextEntry = YES;
CALayer *bottomBorder = [CALayer layer];
bottomBorder.frame = CGRectMake(0.0, 29.0, usernameInput.frame.size.width, 1.0);
bottomBorder.backgroundColor = [UIColor blackColor].CGColor;
CALayer *borderCopy = [CALayer layer];
borderCopy.frame = CGRectMake(0.0, 29.0, passwordInput.frame.size.width, 1.0);
borderCopy.backgroundColor = [UIColor blackColor].CGColor;
[usernameInput.layer addSublayer:bottomBorder];
[passwordInput.layer addSublayer:borderCopy];
[self.view addSubview:usernameInput];
[self.view addSubview:passwordInput];
UILabel *signInButton = [[UILabel alloc] initWithFrame:CGRectMake(0, 270, self.view.bounds.size.width, 60.0)];
signInButton.font = [UIFont fontWithName:#"Montserrat" size:15.0];
signInButton.text = #"Sign In";
signInButton.textColor = [UIColor blackColor];
signInButton.tag = 5;
signInButton.textAlignment = NSTextAlignmentCenter;
CALayer *topButtonBorder = [CALayer layer];
topButtonBorder.frame = CGRectMake(0, 0, self.view.bounds.size.width, 1);
topButtonBorder.backgroundColor = [UIColor blackColor].CGColor;
CALayer *bottomButtonBorder = [CALayer layer];
bottomButtonBorder.frame = CGRectMake(0, 59, self.view.bounds.size.width, 1);
bottomButtonBorder.backgroundColor = [UIColor blackColor].CGColor;
[signInButton.layer addSublayer:topButtonBorder];
[signInButton.layer addSublayer:bottomButtonBorder];
[self.view addSubview:signInButton];
UIView *optionsDivide = [[UIView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width / 2 - 0.5, self.view.bounds.size.height - 45, 1, 20)];
optionsDivide.backgroundColor = [UIColor blackColor];
[self.view addSubview:optionsDivide];
UIButton *tos = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *pp = [UIButton buttonWithType:UIButtonTypeRoundedRect];
tos.frame = CGRectMake(self.view.bounds.size.width / 2 - 115.5 , self.view.bounds.size.height - 65, 110, 60);
pp.frame = CGRectMake(self.view.bounds.size.width / 2 + 0.5 , self.view.bounds.size.height - 65, 110, 60);
[tos setTitle:#"Terms of Service" forState:UIControlStateNormal];
[pp setTitle:#"Privacy Policy" forState:UIControlStateNormal];
pp.titleLabel.textAlignment = NSTextAlignmentLeft;
tos.titleLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:12.0];
pp.titleLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:12.0];
[tos addTarget:self action:#selector(displayTOC:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:tos];
[self.view addSubview:pp];
}
- (void)animateSplashScreen
{
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self.view viewWithTag:2].frame = CGRectMake(0.0, self.view.bounds.size.height / 2.0 - 25.0, self.view.bounds.size.width, 50.0);
}
completion:^(BOOL finished){
[self initializeLoginView];
[UIView animateWithDuration:0.5
delay:1.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[self.view viewWithTag:1].frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 65.0);
[self.view viewWithTag:2].frame = CGRectMake(0.0, 15.0, self.view.bounds.size.width, 50.0);
((UILabel *)[self.view viewWithTag:2]).transform = CGAffineTransformScale(((UILabel *)[self.view viewWithTag:2]).transform, 0.6, 0.6);
}
completion:^(BOOL finished){
((UILabel *)[self.view viewWithTag:2]).font = [UIFont fontWithName:#"Montserrat" size:30.0];
}];
}];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initializeSplashView];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self animateSplashScreen];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//CGPoint locationPoint = [[touches anyObject] locationInView:self.view];
//CGPoint viewPoint = [[self.view viewWithTag:5] convertPoint:locationPoint fromView:self.view];
//if ([[self.view viewWithTag:5] pointInside:viewPoint withEvent:event]) {
// [self.view viewWithTag:5].frame = CGRectMake(self.view.bounds.size.width / 2 - 62.5, 254.5, 130.0, 60.0);
//}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//[self.view viewWithTag:5].frame = CGRectMake(self.view.bounds.size.width / 2 - 67.5, 249.5, 130.0, 60.0);
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
//[self.view viewWithTag:5].frame = CGRectMake(self.view.bounds.size.width / 2 - 67.5, 249.5, 130.0, 60.0);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#end
I copy-pasted your code into a file and found a warning on this line [tos addTarget:self action:#selector(displayTOC:) forControlEvents:UIControlEventTouchUpInside]; The warning says,
Undeclared selector 'displayTOC:'
When I ran the code and tapped the TOC button, it didn't just freeze, it crashed with the error:
-[ViewController displayTOC:]: unrecognized selector sent to instance ...
These should be strong hints on what is wrong in your code. When you ask people about your code, you should reveal any and all warnings, and crashes.
Note, a method named displayTOC is not the same as a method named displayTOC:
By the way, the animation you did is really cool. Good job!

How can i add a stylish white color uialertview with activity indicator

when i press one button i have to display one white color uialertview with activity indicator for 5 seconds ?
i saw some codes and i select the following code ,is that enough? how can i change the color of activity indicator
myAlertView = [[UIAlertView alloc] initWithTitle:#"Loading" message:#"\n\n"
delegate:self
cancelButtonTitle:#""
otherButtonTitles:#"OK", nil];
UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
loading.frame=CGRectMake(150, 150, 16, 16);
[myAlertView addSubview:loading];
i want something like in this image with uiactivity indicator
You can create a custom alert like follow (PS: i had developed this custom alert after 3 hours of working, its compatible with iPhone4, iPhone5 and iPad ):
-(void)showAlert{
alertViewView = [[UIView alloc]initWithFrame:self.window.frame];
UIImageView *alertBackground = [[UIImageView alloc]initWithFrame:CGRectMake(-200, -200, self.window.frame.size.width*2, self.window.frame.size.height*2)];
// alertBackground.image = [UIImage imageNamed:#"alertBackGround.png"];
[alertViewView addSubview:alertBackground];
alertBackground.backgroundColor = [UIColor blackColor];
alertBackground.alpha = 0.5;
UIImageView *alertImage = [[UIImageView alloc]initWithFrame:CGRectMake(self.window.frame.size.width/2-310/2, self.window.frame.size.height/2-179/2, 310, 248)];
alertImage.image = [UIImage imageNamed:#"rommanAlertBig.png"];
[alertViewView addSubview:alertImage];[alertBackground release];[alertImage release];
UIButton *lButton = [UIButton buttonWithType:UIButtonTypeCustom];
lButton.frame = CGRectMake(self.view.frame.size.width/2-150+40-15, self.view.frame.size.height/2-179/2+118 , 120, 41);
[lButton setTitle:#"Cancel" forState:UIControlStateNormal];
[lButton addTarget:self action:#selector(removeAlert) forControlEvents:UIControlEventTouchUpInside];
[alertViewView addSubview:lButton];
UIButton *rButton = [UIButton buttonWithType:UIButtonTypeCustom];
rButton.frame = CGRectMake(self.view.frame.size.width/2-150+170-15, self.view.frame.size.height/2-179/2+118 , 120, 41);
[rButton setTitle:#"OK" forState:UIControlStateNormal];
[rButton addTarget:self action:#selector(yesAction) forControlEvents:UIControlEventTouchUpInside];
[alertViewView addSubview:rButton];
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(self.window.frame.size.width/2-310/2+30, self.window.frame.size.height/2-179/2+75, 260, 40+69)];
lbl.text = #"Description";
lbl.textColor = [UIColor whiteColor];
lbl.textAlignment =UITextAlignmentCenter;
lbl.numberOfLines = 0;
lbl.font = [UIFont systemFontOfSize:17.0];
lbl.backgroundColor = [UIColor clearColor];
[alertViewView addSubview:lbl];[lbl release];
[self.window addSubview:alertViewView];
alertViewView.alpha = 0;
[UIView animateWithDuration:0.1 animations:^{alertViewView.alpha = 1.0;}];
alertViewView.layer.transform = CATransform3DMakeScale(0.5, 0.5, 1.0);
CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:#"transform.scale"];
bounceAnimation.values = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.5],
[NSNumber numberWithFloat:1.1],
[NSNumber numberWithFloat:0.8],
[NSNumber numberWithFloat:1.0], nil];
bounceAnimation.duration = 0.3;
bounceAnimation.removedOnCompletion = NO;
[alertViewView.layer addAnimation:bounceAnimation forKey:#"bounce"];
alertViewView.layer.transform = CATransform3DIdentity;
}
-(void)removeAlert{
for (UIView *v in [alertViewView subviews]) {
[v removeFromSuperview];
}
[alertViewView removeFromSuperview];
[alertViewView release];
}
-(void)yesAction
{ [self removeAlert];
// Your Code here
}
Change color of activity indicator
In iOS 5.0 and up you can use setColor: on the UIActivityIndicatorView to set a custom color.
MAke a custom alertview
make a subclass
In drawrect draw white color on top of the view part
Why not use the class you took the picture from? https://github.com/m1entus/WCAlertView
For the ActivityIndicator you can just drag one out with the IB and change its color. Then do something like :
[activityindicator startanimating];
//put alert code here
// choose when you want to stop the animation:
//[activityindicator stopanimating];

How to make the SubView of a UIView, placed out of UIView frame, interactive?

I have added a UIView to a View of a View Controller. Say:
CGRect paneRect = {10.0f, 10.0f, 300.0f, 50.0f};
UIView *pane = [[UIView alloc] initWithFrame:paneRect];
pane.backgroundColor = [UIColor greenColor];
pane.userInteractionEnabled = YES;
pane.clipsToBounds = NO;
[self.view addSubview:pane];
Then I've added a UIButton to pane:
CGRect testRect = {10.0f, 25.0f, pane.frame.size.width - 20.0f, 50.0f};
UIButton *test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[test setTitle:#"test" forState:UIControlStateNormal];
[test setFrame:testRect];
[pane addSubview:test];
Now half of the "test" button is within the pane and the other half is out. The upper half is interactive and responds to touches however the lower half is not.
Is it possible to make the whole "test" button interactive and touchable instead of its half?
If you really want to make these view stick with each other then you can do some thing like this
CGRect mainViewRect = {10.0f, 10.0f, 300.0f, 75.0f};
UIView *mainView = [[UIView alloc] initWithFrame:mainViewRect];
mainView.backgroundColor = [UIColor clearColor];
mainView.userInteractionEnabled = YES;
[self.view addSubview:mainView];
CGRect paneRect = {0.0f, 0.0f, 300.0f, 50.0f};
UIView *pane = [[UIView alloc] initWithFrame:paneRect];
pane.backgroundColor = [UIColor greenColor];
pane.userInteractionEnabled = YES;
pane.clipsToBounds = NO;
[mainView addSubview:pane];
CGRect testRect = {10.0f, 25.0f, pane.frame.size.width - 20.0f, 50.0f};
UIButton *test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[test setTitle:#"test" forState:UIControlStateNormal];
[test setFrame:testRect];
[mainView addSubview:test];
just do Like this Way
CGRect paneRect = {10.0f, 10.0f, 300.0f, 50.0f};
UIView *pane = [[UIView alloc] initWithFrame:paneRect];
pane.backgroundColor = [UIColor greenColor];
pane.userInteractionEnabled = NO;
pane.clipsToBounds = NO;
[self.view addSubview:pane];
CGRect testRect = {10.0f, 25.0f, pane.frame.size.width - 20.0f, 50.0f};
UIButton *test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[test setTitle:#"test" forState:UIControlStateNormal];
test.userInteractionEnabled = YES;
[test setFrame:testRect];
[pane addSubview:test];
For Action of UIButton just add
[test addTarget:self action:#selector(processButtonCLick) forControlEvents:UIControlEventTouchUpInside];
If you want to uibutton center of pane Add
test.center =pane.center;

Resources