wimagguc / ios-custom-alertview Goto Github PK
View Code? Open in Web Editor NEWCustom UIAlertView. Continue adding images and UIViews to dialogs in iOS7+
License: Other
Custom UIAlertView. Continue adding images and UIViews to dialogs in iOS7+
License: Other
Add a text field to an uiview.
Set textfield as first responder.
Set above uiview with setContainerView.
Call show on custom alertview.
Sometimes custom alertview is shown above the keyboard which renders the keyboard unresponsive to touch events.
Hi, thanks for making this, it saved a bunch of work. However, while investigating if there was some way of changing the font on the cancel button, I found the buttonView property. It does not seem to be referenced anywhere, so i think it may be bit rot. Was there some intended purpose for this property?
Hi, any plans on refining the support for orientation changes on iPad?
-[__NSArrayI release]: message sent to deallocated instance 0x9b1fcb0
I saw that some people (like me) had in some project the alert view not displayed.
I discovered (in my case) that it was because the view is attached to a wrong window (don't ask my why but my project seems to have two, i suspect another library needs it).
Si if you replace in the CustomIOS7AlertView.m the line
[[[[UIApplication sharedApplication] windows] firstObject] addSubview:self];
by this one:
[[[[UIApplication sharedApplication] delegate] window] addSubview:self];
The problem disappear. The question is then: Why isn't it the default behavior? Why is it better to test the first object of the window array?
This isn't so much an issue with your code, but I'm adding a subview, which has a uitextfield in it.
However, I need to resign the keyboard if the user taps elsewhere on the view.
So I guess I need an event if the subview is tapped ? which doesn't dismiss the alertview and keep on processing other events like buttons.
Any suggestions, maybe I've overlooked a very simple solution?
Thanks in advance.
If you run the analyzer you get the following warning: Instance variable used while 'self' is not set to the result of '[(super or self) init...]'.
It can be addressed by changing the code to:
- (id)initWithParentView: (UIView *)_parentView
{
self = [self init];
if (_parentView) {
self.frame = _parentView.frame;
self.parentView = _parentView;
}
return self;
}
I understand that the method is going away, but for the time being it is best not the have the analyzer warning, especially for projects where such warnings will cause the build to fail.
Please remove NSLog(...) in this line. Thanks for building this awesome control!
I have used exactly the same code given in the demo, just to test how this works, and the alert isn't showing. This is the code:
CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] init];
//It works only when using initwithparentview
// Add some custom content to the alert view
[alertView setContainerView:[self createDemoView]];
// Modify the parameters
[alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"Close1", @"Close2", @"Close3", nil]];
[alertView setDelegate:self];
// You may use a Block, rather than a delegate.
[alertView setOnButtonTouchUpInside:^(CustomIOS7AlertView *alertView, int buttonIndex) {
NSLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, [alertView tag]);
[alertView close];
}];
[alertView setUseMotionEffects:true];
// And launch the dialog
[alertView show];
The init is not working, I have used the deprecated version, the one with initWithParentView, and it works just fine.
I'm adding a uitextview into a view, and add this view in ios7alertview content, and the keyboard does not appear.
I'm doing something wrong, or there is a bug?
Code:
int width = self.view.frame.size.width - 30;
CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] initWithFrame:CGRectMake(0, 0, width, 130)];
UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 130)];
UITextField *title = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, width, 30)];
[title setTextAlignment:NSTextAlignmentCenter];
[title setFont:[UIFont boldSystemFontOfSize:15]];
[title setText:@"Reprove"];
UITextField *message = [[UITextField alloc] initWithFrame:CGRectMake(0, 30, width, 30)];
[message setTextAlignment:NSTextAlignmentCenter];
[message setText:@"Message"];
UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(10, 60, width - 20, 60)];
[textView.layer setCornerRadius:7];
[alertView setContainerView:mainView];
[mainView addSubview:title];
[mainView addSubview:message];
[mainView addSubview:textView];
[alertView setUseMotionEffects:YES];
[alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"Cancel", @"Reprove", nil]];
[alertView show];
[textView becomeFirstResponder];
I'm using xCode 6.1.1 and iOS 8.1
(In this image, the textview are focused)
Thanks
I have tried the demo app in iPad mini. The background view doesn't change its frame on orientation change and also the alertview shows wrong orientation
Having intuition that this would become the best alternative to add a subview in alert view and use in iOS7 too. I'm reaching here, when I really need to change my code which need to have a custom alert view for iOS7 too. It's well implemented for iOS7. But it also looks same UI for lesser versions that's iOS 6. You should detect current iOS version and based on that provide UI for previous look and new UI look.
I tried to show the CostumAlert when you start the application but this does not appear. in method viewDidLoad of delegate could help than
Hello,
In the current implementation the alertView is attached to a view which is not the expected behavior from an alert. This is a problem in those case when there is a visible keyboard on the screen . Check this screenshot:
https://www.dropbox.com/s/xufacehfgi1dbfq/Screenshot%202013-09-30%2015.19.17.png
The alertView should be attached to the front most window. Something like:
[[UIApplication sharedApplication].windows.lastObject addSubview:self];
This way the parentView
is not needed anymore.
Cheers,
StaS
Why not contain the UIView in a UIViewController, and then implement willRotateToInterfaceOrientation?
The included project CustomIOS7AlertView.xcodeproj
doesn't build as is with Xcode 6.1. The error is error: could not read data from 'ios-custom-alertview/CustomIOS7AlertView/CustomIOS7AlertViewTests/CustomIOS7AlertViewTests-Info.plist': The file “CustomIOS7AlertViewTests-Info.plist” couldn’t be opened because there is no such file
. With 6.x Xcode will build the unit test target even if it is not the current target. The quickest solution to this is just removing the unit test target, since there are no unit tests.
If I have a lot of alert views, I tag them to identify properly in controller delegate method. We need to create more comfortable way to do it (pass a tag in the delegate method, put some methods so users can tag buttons, etc?)
Here is how I do it now
Creating alert view(s)
-(void)makeAlert:(NSIndexPath*)indexPath {
CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] initWithParentView:self.view];
alertView.tag = 1;
[alertView setDelegate:self];
[alertView show];
}
Detecting that exactly the alert view above was closed
- (IBAction)customIOS7dialogButtonTouchUpInside:(id)sender
{
NSLog(@"Button at position %d is clicked.", [sender tag]);
NSLog(@"Alert View Tag: %d", [[[sender superview] superview] tag]);
}
There is one major bug in the code. While I am running an app in iPad Landscape mode , having a keyboard opened (Say I am editing in textfield) , now if Alert is popped-up ... And I am rotating my iPad from Landscape to portrait mode at that time alertView's position is changing . Its a strange behaviour. Please update.
Hi,
I have integrated this in my existing project, it works fine while running app in iOS 7 but in iOS 6 crashes as soon as app launch with the following error.
dyld: Symbol not found: OBJC_CLASS$_UIInterpolatingMotionEffect
Thanks!
I'm trying to install it using cocoapods but can not find a specification for this library:
I leave my PODFILE:
platform: ios, '7.0'
pod "CustomIOS7AlertView", "~> 0.81"
thanks!
If you scroll down a page in table view and then select a cell that displays CustomIOS7AlertView, the view is located at the top of the table. Need to add following code to CustomIOS7AlertView show method.
if ([parentView isKindOfClass:[UITableView class]]) {
UITableView *tableView = (UITableView *)parentView;
self.frame = CGRectMake(tableView.contentOffset.x, tableView.contentOffset.y, tableView.bounds.size.width, tableView.bounds.size.height);
}
I placed code immediately after [parentView addSubview:self];
Default UIAlertView having this delegate method, -(void)willPresentAlertView:(UIAlertView *)alertView
Do we've the same method for custom alert. It'll be really helpful to merge the existing code.
I'm using a custom alertView to indicate the loading of a UIWebView but it crashes with a bad access message. Without the setButtonTitles line it works fine.
-(void)webViewDidStartLoad:(UIWebView *)webView
{
alert = [[CustomIOS7AlertView alloc]initWithParentView:self.view];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0,10,240,100)];
[spinner startAnimating];
UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 240, 100)];
UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(0, -30, 240, 100)];
[demoView addSubview:spinner];
[demoView addSubview:label];
[alert setContainerView:demoView];
[alert setButtonTitles:NULL];
[alert show];
}
Hey!
Great little project you have here.
It would be great if you added it to cocoapods!
Cheers,
Andreas
I added this into my pod file. -> pod install.
When i run the app ->
ld: library not found for -lPods-CustomIOSAlertView
well.. simple as that... is there a way to change buttons fonts?
This closes the alertView, but not the grey overlay. Appeared on iOS 8.1
When I change the rootViewController in AppDelegate after first App lunch, the Alertview doesn't appear at all. whereas it's working before changing the rootViewController.
Thanks in Advance.
I can't get this thing to display landscape mode. You tried to control it so much aesthetically that it became stupid difficult to have it show in landscape orientation.
Currently it can't rotation with the device rotation.
Hi there,
everytime when I try to use multiple buttons I got a crash. The view is shown, I see the buttons and then the app crashes with a EXEC_BAD_ACCESS
If I remove the "extra" Buttons everything is fine.
Am I missing something or is this a bug?
CustomIOS7AlertView *ALERT = [[[CustomIOS7AlertView alloc] initWithParentView:self.view]autorelease];
[ALERT setButtonTitles:[NSMutableArray arrayWithObjects:@"Button1", @"Button2", @"Button3", nil]];
Hi,
There's a behavior I would like to be improved. When the alert is displayed, the status bar doesn't darken as it gets when it calls the UIAlertView.
Any ideas how to fix this?
Thanks!
Hi guys, I wondering, how can I add uitableview in the Alert?
In my app I have an uitableview and if the user press in one row is going to show a dialog with a table (the table have some action).
May I made this behavior with your alertview?
Regards,
David
what about auto rotate based the orientation of the device.???
Hello,
I am still facing rotation issue in iPad 2.0 with iOS 8.0. I m sure iPad mini will have still the same issue
See the images..Issues is in Landscape orientations.. AlertView's background is not getting resized and hence Alert is not displayed in the centre.
If I open an alert in Portrait mode, and change device's orientation to Landscape, at that time there is some problem in resizing the screenSize. And due to this , Alert is not displayed in the center of the screen
Have to modify the orientationDidChange code as it is only working currently with OS 7.1 or lower version. Transformation is not handled properly
Hi,
I seem to be getting a Bad_Access crash whenever I set the buttons of the Custom AlertView. I noticed in another bug reported (#32) it was asked if the project was an arc based one.
However my project is not an arc based one, and I cannot change it because I'm using it as part of an iOS plugin for Unity3D which generates and uses non arc supported code.
I needed a custom alert view - great. But I just wanted the user to be able to touch anywhere on the dialog for it to go away. The default behavior, no buttons, just sites there. How about something simple like, in addButtonsToView... (i.e., this works perfectly for my needs...) Thanks again!
if (buttonTitles==NULL) {
UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[closeButton setFrame:CGRectMake(0, 0, container.bounds.size.width, container.bounds.size.height)];
[closeButton addTarget:self action:@selector(customIOS7dialogButtonTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
[container addSubview:closeButton];
return;
}
when I set a UITableView be a container view,
UITableView shows wrong in iOS8.
CustomIOS7AlertView.m
line:82 dialogView.layer.transform = CATransform3DMakeScale(1.3f, 1.3f, 1.0);
// i try to fix it ... but... it is still shows wrong :(
dialogView.layer.transform = CATransform3DMakeScale(1.2f, 1.78f, 1.0);
Can't see this on cocoapods.org
Tried...
pod 'CustomIOSAlertView', '~> 0.9.2'
I get the following error?
[!] Unable to satisfy the following requirements:
CustomIOSAlertView (~> 0.9.2)
required by Podfile
CustomIOSAlertView (~> 0.9.2)
required by Podfile
Hi,
First of all, thank you for your great work !
I have an issue, I created a single view application (a Calculator app because i'm a beginner), and I use your project to show a UIAlert pop up message. It works fine unitl I press the "Close" button. I have a single view but I don't know why the close button make the app crash :/
I do the following in my CalculatorViewController.m :
Thank you for your help !!
Sincerely,
S.B.
I added a textfield on the containerview ,but when i want to input some words the keyboard was covered!!!
I discovered another strange behavior (maybe linked to IOS8, never appeared before...).
In my projects, the alertview is not defined programmatically but with storyboards. I instantiate the view, store in my current controller after the first call and reuse it (and attach as content) in my alert view next time i need it.
For an unknown reason, the first time the alert view size is correct, but every following call will scale my view :-D
For example:
1st call: 300x160
2nd call: 500x300.5
3rd call: 833x535
I discover that the view change during the close method, when the "animateWithDuration" block is called. I suspect the CATransform3DConcat modify my view size.
This problem might comes from my project also because i use this library for a long time and never had any problem. I just posted this to know if someone else had the same issue.
To resolve this problem (temporary because i don't like the following solution), i just recall the "instantiateViewControllerWithIdentifier" method everytime i need the alertview content.
Regards
I have used the same code. Added the delegate and imported the header file. Still Alert not showing up
(IBAction)contactUs:(id)sender
{
// Here we need to pass a full frame
CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] init];
[alertView setContainerView:[self createDemoView]];
[alertView setBackgroundColor:[UIColor blackColor]];
[alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"Close", nil]];
[alertView setDelegate:self];
[alertView setOnButtonTouchUpInside:^(CustomIOS7AlertView *alertView, int buttonIndex) {
NSLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, [alertView tag]);
[alertView close];
}];
//[alertView setUseMotionEffects:true];
// And launch the dialog
[alertView show];
}
(void)customIOS7dialogButtonTouchUpInside: (CustomIOS7AlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex
{
[alertView close];
}
(UIView *)createDemoView
{
UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 400)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 150)];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont fontWithName:@"helveticaNeue-Bold" size:13];
label.textColor = [UIColor grayColor];
label.numberOfLines = 12;
label.lineBreakMode = NSLineBreakByWordWrapping;
label.text = [NSString stringWithFormat:@"ssdmfbs shbf ,jsdhf b,shf b,shdfb ,sdfb ,sdfb ,sdjfb ,sdjfb,djksfbdjksf.skjdf.ksjdfh.ksjfdh.skjdfh.skjdfh.skjdfh"];
[demoView addSubview:label];
return demoView;
}
Hello,
I am setting the demoView tag in createDemoView as below
[demoView setTag] = 1;
but customAlertView does not seem to receive it and the tag is always 0. Any thoughts please
First, Thank for your source code, with it, I can replace old alert version using add subview method and compatible with iOS 7.
But when I integrated it with UITextField , UITextView or something based on system.
In my case, I had a TextField in a landscape orientation. After editing textfield content, I show a your ALERT. But it displayed wrong.
Please see my photo.
Before Editing textfiled: https://dl.dropboxusercontent.com/u/31985459/problems/alert7.0a.png
After Editing testfield: https://dl.dropboxusercontent.com/u/31985459/problems/alert7.0b.png
And then, I fixed it like that:
Change from:
[[[[UIApplication sharedApplication] windows] lastObject] addSubview:self]; //line 108 or 109 your code.
to:
[[[[UIApplication sharedApplication] delegate] window] addSubview:self];
After all, Thank you.
Hey guys,
I've tried to simply self init and even to super init, but no success.. Do you have a clue why?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.