v0.9.3
support for both iOS7 and iOS8
The addSubview is not available in UIAlertView in iOS7 or iOS8 any more. The view hierarchy for this class is private and must not be modified.
As a solution, this class creates an iOS-style dialog which you can extend with any UIViews or buttons. The animations and the looks are copied too and no images or other resources are needed.
As simple as adding the following files to your project:
- CustomIOSAlertView.h
- CustomIOSAlertView.m
Or use Cocoapods:
pod 'CustomIOSAlertView', '~> 0.9.3'
-
Fixed rotation for IOS8
-
Removed 7 from the class name. Just use CustomIOSAlertView from now on, like: [[CustomIOSAlertView alloc] init];
-
The initWithParentView method is now deprecated. Please use the init method instead, where you don't need to pass a parent view at all. In case the init doesn't work for you, please leave a note or open an issue here.
-
Create the UIView object
changed
CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
-
Add some custom content to the alert view (optional)
UIView *customView ..; [alertView setContainerView:customView];
Display the dialog
[alertView show];
-
Close the dialog
[alertView close];
-
To add more buttons, pass a list of titles
[alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"Button1", @"Button2", @"Button3", nil]];
-
You can remove all buttons by passing nil
[alertView setButtonTitles:NULL];
-
You can enable or disable the iOS7 parallax effects on the alert view
[alertView setUseMotionEffects:TRUE];
-
Handle button clicks with a custom delegate
First, set the delegate:
[alertView setDelegate:self];
Then add the delegate methods:
- (void)customIOS7dialogButtonTouchUpInside: (CustomIOSAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex { NSLog(@"Button at position %d is clicked on alertView %d.", buttonIndex, [alertView tag]); }
Handle button clicks with a code block
[alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) { NSLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, [alertView tag]); [alertView close]; }];
You can also disable all other delegates by:
[alertView setDelegate:self]; ```
This is a really quick implementation, and there are a few things missing:
-
Adding more buttons: they don't exactly match the look with that of on iOS7
-
Rotation: rotates wrong with the keyboard on
- @tamasdancsi for his support with the initial code
- @dingosky for his work on the parallax effects code
- @raspu for his work on the protocol delegates, iOS6 support and onButtonClick blocks
- @sbandol for his idea on adding the AlertView as the top most view in the hierarchy
- @scorpiozj for his work on the rotation code
- @kwent for adding performance optimisations
- @thomasaw for the refract on the deprecated initWithParentview
MIT. Please read LICENSE.md for more info.
Check out AppWoodoo for push notifications and remote app control service. Open source SDKs are available on Github: github.com/appwoodoo.
Some more of my free stuff for web devs at Github.
Project updates newsletter
Richard Dancsi
www.wimagguc.comtwitter: @wimagguc
linkedin: linkedin.com/in/richarddancsi
gplus: plus.google.com/u/0/115939246085616544919ios-custom-alertview's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.