要运行示例项目,先克隆仓库,然后从 Example 目录中首先运行 pod install
。
将 MSAlertControllerStyleAlert
设置为 preferredStyle。
MSAlertController *alertController = [MSAlertController alertControllerWithTitle:@"MSAlertController" message:@"This is MSAlertController." preferredStyle:MSAlertControllerStyleAlert];
MSAlertAction *action = [MSAlertAction actionWithTitle:@"Cancel" style:MSAlertActionStyleCancel handler:^(MSAlertAction *action) {
//Write a code for this action.
}];
[alertController addAction:action];
MSAlertAction *action2 = [MSAlertAction actionWithTitle:@"Destructive" style:MSAlertActionStyleDestructive handler:^(MSAlertAction *action) {
//Write a code for this action.
}];
[alertController addAction:action2];
MSAlertAction *action3 = [MSAlertAction actionWithTitle:@"Default" style:MSAlertActionStyleDefault handler:^(MSAlertAction *action) {
//Write a code for this action.
}];
[alertController addAction:action3];
[self presentViewController:alertController animated:YES completion:nil];
将 MSAlertControllerStyleActionSheet
设置为 preferredStyle。
MSAlertController *alertController = [MSAlertController alertControllerWithTitle:@"MSAlertController" message:@"This is MSAlertController." preferredStyle:MSAlertControllerStyleActionSheet];
MSAlertAction *action = [MSAlertAction actionWithTitle:@"Cancel" style:MSAlertActionStyleCancel handler:^(MSAlertAction *action) {
//Write a code for this action.
}];
[alertController addAction:action];
MSAlertAction *action2 = [MSAlertAction actionWithTitle:@"Destructive" style:MSAlertActionStyleDestructive handler:^(MSAlertAction *action) {
//Write a code for this action.
}];
[alertController addAction:action2];
MSAlertAction *action3 = [MSAlertAction actionWithTitle:@"Default" style:MSAlertActionStyleDefault handler:^(MSAlertAction *action) {
//Write a code for this action.
}];
[alertController addAction:action3];
[self presentViewController:alertController animated:YES completion:nil];
@property (strong, nonatomic) UIColor *titleColor;
@property (strong, nonatomic) UIFont *titleFont;
@property (strong, nonatomic) UIColor *messageColor;
@property (strong, nonatomic) UIFont *messageFont;
@property (assign, nonatomic) BOOL enabledBlurEffect;
@property (strong, nonatomic) UIColor *backgroundColor;
@property (assign, nonatomic) CGFloat alpha;
@property (strong, nonatomic) UIColor *alertBackgroundColor;
@property (strong, nonatomic) UIColor *separatorColor;
MSAlertController *alertController = [MSAlertController alertControllerWithTitle:@"MSAlertController" message:@"This is MSAlertController." preferredStyle:MSAlertControllerStyleAlert];
alertController.titleColor = [UIColor blueColor];
alertController.titleFont = [UIFont fontWithName:@"Baskerville-BoldItalic" size:20.0f];
alertController.messageColor = [UIColor greenColor];
alertController.messageFont = [UIFont fontWithName:@"Baskerville-BoldItalic" size:18.0f];
@property (strong, nonatomic) UIColor *titleColor;
@property (strong, nonatomic) UIFont *font;
@property (strong, nonatomic) UIColor *normalColor;
@property (strong, nonatomic) UIColor *highlightedColor;
MSAlertAction *action = [MSAlertAction actionWithTitle:@"Cancel" style:MSAlertActionStyleCancel handler:^(MSAlertAction *action) {
//Write a code for this action.
}];
action.titleColor = [UIColor redColor];
action.font = [UIFont fontWithName:@"Baskerville-BoldItalic" size:18.0f];
[alertController addAction:action];
MSAlertController *alertController = [MSAlertController alertControllerWithTitle:@"MSAlertController" message:@"This is MSAlertController." preferredStyle:MSAlertControllerStyleAlert];
alertController.alertBackgroundColor = [UIColor lightGrayColor];
alertController.backgroundColor = [UIColor blueColor];
alertController.alpha = 0.3f;
alertController.separatorColor = [UIColor redColor];
MSAlertAction *action = [MSAlertAction actionWithTitle:@"Cancel" style:MSAlertActionStyleCancel handler:^(MSAlertAction *action) {
NSLog(@"Cancel action tapped %@", action);
}];
action.normalColor = [UIColor blackColor];
action.highlightedColor = [UIColor yellowColor];
[alertController addAction:action];
MSAlertAction *action2 = [MSAlertAction actionWithTitle:@"Destructive" style:MSAlertActionStyleDestructive handler:^(MSAlertAction *action) {
NSLog(@"Destructive action tapped %@", action);
}];
[alertController addAction:action2];
MSAlertAction *action3 = [MSAlertAction actionWithTitle:@"Default" style:MSAlertActionStyleDefault handler:^(MSAlertAction *action) {
NSLog(@"Default action tapped %@", action);
}];
action3.normalColor = [UIColor darkGrayColor];
action3.highlightedColor = [UIColor whiteColor];
[alertController addAction:action3];
[alertController addTextFieldWithConfigurationHandler:nil];
[self presentViewController:alertController animated:YES completion:nil];
动作表与相同的自定义兼容。
此项目的一个示例使用 "SACollectionViewVerticalScalingFlowLayout"来应用缩放效果以实现滚动。
Taiki Suzuki,[email protected]
MSAlertController 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。