Recently while developing an iPhone application I needed to display a message box which is similar to UIAlertView but which could be modified by adding different objects like Activity indicator. I also wanted to replicate animation of UIAlertView. I created my custom alert view which I would like to post here. I hope some of the techniques I have used here could be useful to other developers. You can download code from github repository. Please note that I have taken some ideas from Brad Larson's iTunes lecture: Quartz 2D drawing. Here is how the Custom alert view looks like.
CustomAlertView class :
First we need to create a CustomAlertView class in our project. This class is derived from UIView class.
Implement init method
Init method will receive frame and the text which needs to be displayed.
CustomAlertView class :
First we need to create a CustomAlertView class in our project. This class is derived from UIView class.
Implement init method
Init method will receive frame and the text which needs to be displayed.
-(id)initWithFrame:(CGRect)frame withText:(NSString*)text{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
[self initTextLabel:text];
[self initActivityIndicator];
}
return self;
}
We call initTextLabel function which creates label and adjusts its position. The second function initActivityIndicator adjusts activity indicator control.