Your application is almost ready. You have implemented all screens. However, there is an error coming from the server and you should display a message about it. This is a common situation, but what's the solution? You could use one of the following alternatives:
The good news: in iOS there is a component that shows alerts-UIAlertView. In iOS 8 it was deprecated and replaced with UIAlertController. UIAlertController has an easy-to-use block API. However, this component has two drawbacks: it is available only in iOS 8 and it can't be customized at all. You will get only the basic iOS look.
This gives you complete control over the UI and behavior. However, managing view transitions is not that easy and straightforward. You should handle different cases like device rotation for example and it needs to be tested on different devices. Before you know it, you're working late and the final deadline is coming.
There are many open source alternatives. Some of them look good, almost. Most often, those components are built for specific purpose and there is no documentation. When you start using them, you find that in order to get the necessary look and behavior, you should combine at least two different components. You start thinking about creating your own alert from scratch.
TKAlert *alert = [TKAlert
new
];
alert.title = @
"Warning"
;
alert.message = @
"Are you ready for TKAlert?"
;
alert.style.appearAnimation = TKAlertAnimationSlideFromTop;
alert.alertView.layer.shadowOpacity = 0.6;
alert.alertView.layer.masksToBounds = NO;
[alert show:YES];
TKAlertAction *action = [alert addActionWithTitle:@
"Yes"
handler:^BOOL(TKAlert *alert, TKAlertAction* action) {
return
YES;
}];
action.backgroundColor = [UIColor colorWithRed:0.882f green:0.882f blue:0.882f alpha:1.00f];
action.titleColor = [UIColor colorWithRed:0.302f green:0.302f blue:0.302f alpha:1.00f];
action.cornerRadius = 3;
alert.delegate = self;
- (void)alertDidShow:(TKAlert *)alert
{
TKView *view = [[TKView alloc] initWithFrame:CGRectMake(20, -30, 60, 60)];
view.shape = [TKPredefinedShape shapeWithType:TKShapeTypeCircle andSize:CGSizeZero];
view.fill = [TKSolidFill solidFillWithColor:[UIColor colorWithRed:0.961f green:0.369f blue:0.306f alpha:1.00f]];
view.stroke = [TKStroke strokeWithColor:[UIColor whiteColor] width:3.0];
view.transform = CGAffineTransformMakeScale(0.1, 0.1);
[alert.alertView addSubview:view];
[UIView animateWithDuration:0.7
delay:0.0
usingSpringWithDamping:0.3
initialSpringVelocity:0.2
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
view.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
}];
}
Tsvetan is the Team Leader of the UI for iOS team. He has been part of Telerik since 2006, when he joined the company as regular developer in the WinForms team. Tsvetan made his way through all developer postions over the past few years. His addiction to the cutting edge technologies, together with the passion to develop outstanding products are what drive him forward. In his spare time Tsvetan loves biking, hiking and snowboarding. You can find Tsvetan on Twitter @tzraikov, and LinkedIn.