Alert: Customizations

TKAlert allows customizing almost every aspect of its visual appearance. This article demonstrates some of the customization techniques that can be used with it.

TKAlert comes with two predefined actions layouts. You can choose between:

You can switch between layouts by setting TKAlert's property actionsLayout:

_alert.actionsLayout = TKAlertActionsLayoutVertical;
alert.actionsLayout = TKAlertActionsLayout.vertical
alert.ActionsLayout = TKAlertActionsLayout.Vertical;

TKAlert has a property style of type TKAlertStyle for styling it's appearance. The essential properties of TKAlertStyle class are:

You can switch between two customizable background styles - Blur and Dim.

Background type Figures
Dim
Blur
None

Setting TKAlert's back behind could be done as follows:

_alert.style.backgroundStyle = TKAlertBackgroundStyleNone;
alert.style.backgroundStyle = TKAlertBackgroundStyle.none
alert.Style.BackgroundStyle = TKAlertBackgroundStyle.None;

You can control background's opacity and color by setting TKAlert's style as follows:

alert.style.backgroundDimAlpha = 0.5;
alert.style.backgroundTintColor = [UIColor lightGrayColor];
alert.style.backgroundDimAlpha = 0.5;
alert.style.backgroundTintColor = UIColor.lightGray
alert.Style.BackgroundDimAlpha = 0.5f;
alert.Style.BackgroundTintColor = UIColor.LightGray;

TKAlert's parallax effect could be turned on/off with single line of code:

alert.allowParallaxEffect = YES;
alert.allowParallaxEffect = true
alert.AllowParallaxEffect = true;

Custom Content

In some scenarios you may need to use custom views for TKAlert header or content view. TKAlert allows this by using its headerView and contentView properties:

TKAlert *alert = [TKAlert new];
alert.style.headerHeight = 0;
alert.tintColor = [UIColor colorWithRed:0.5 green:0.7 blue:0.2 alpha:1];
alert.customFrame = CGRectMake(0, 0, 300, 250);
AlertCustomContentView *view = [[AlertCustomContentView alloc] initWithFrame:CGRectMake(0, 0, 300, 210)];
[alert.contentView addSubview:view];
let alert = TKAlert()
alert.style.headerHeight = 0
alert.tintColor = UIColor(red: 0.5, green: 0.7, blue: 0.2, alpha: 1)
alert.customFrame = CGRect(x: (self.view.frame.size.width - 300)/2, y: 100, width: 300, height: 250)
let view = AlertCustomContentView(frame: CGRect(x: 0, y: 0, width: 300, height: 210))
alert.contentView.addSubview(view)
TKAlert alert = new TKAlert ();
alert.Style.HeaderHeight = 0;
alert.TintColor = new UIColor (0.5f, 0.7f, 0.2f, 1f);
alert.CustomFrame  = new CGRect ((this.View.Frame.Size.Width - 300) / 2, 100, 300, 250);
AlertCustomContentView view = new AlertCustomContentView (new CGRect(0, 0, 300, 210));
alert.ContentView.AddSubview (view);