forked from OskarZhang/RKDropdownAlert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewController.m
87 lines (71 loc) · 3.28 KB
/
ViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// ViewController.m
// SlingshotDropdownAlert
//
// Created by Richard Kim on 8/26/14.
// Copyright (c) 2014 Richard Kim. All rights reserved.
//
#import "ViewController.h"
#import "RKDropdownAlert.h"
@interface ViewController () <UITextFieldDelegate>
@property (nonatomic) UITextField* titleTextField;
@property (nonatomic) UITextField* messageTextField;
@end
@implementation ViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tapGesture];
self.titleTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width * 0.7, 40)];
self.titleTextField.center = CGPointMake(self.view.frame.size.width / 2, 120);
self.titleTextField.placeholder = @"title";
self.titleTextField.delegate = self;
self.titleTextField.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.05];
self.titleTextField.layer.cornerRadius = 5.0;
[self.titleTextField setTextAlignment:NSTextAlignmentCenter];
[self.view addSubview:self.titleTextField];
self.messageTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width * 0.7, 40)];
self.messageTextField.center = CGPointMake(self.view.frame.size.width / 2, 170);
self.messageTextField.placeholder = @"message";
self.messageTextField.delegate = self;
self.messageTextField.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.05];
self.messageTextField.layer.cornerRadius = 5.0;
[self.messageTextField setTextAlignment:NSTextAlignmentCenter];
[self.view addSubview:self.messageTextField];
UIButton* alertButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
alertButton.center = CGPointMake(self.view.frame.size.width / 2, CGRectGetMaxY(self.messageTextField.frame) + alertButton.frame.size.height);
[alertButton setTitle:@"show alert" forState:UIControlStateNormal];
[alertButton setTitleColor:[UIColor colorWithRed:0.22 green:0.31 blue:0.80 alpha:1] forState:UIControlStateNormal];
[alertButton addTarget:self action:@selector(showDemoAlert) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:alertButton];
}
- (void)showDemoAlert {
//%%% quick and dirty: calls all default values
NSString* title = self.titleTextField.text;
NSString* message = self.messageTextField.text;
if (title.length == 0 && message.length == 0) {
[RKDropdownAlert show];
} else {
[RKDropdownAlert title:title message:message backgroundColor:nil textColor:nil time:5];
}
// other examples:
// [RKDropdownAlert title:@"Hello World"];
// [RKDropdownAlert title:@"Hello World" message:@"Tons better than UIAlertView!" time:1];
// %%% etc. check the .h to see all the different ways you can call this function
}
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
- (void)dismissKeyboard {
[self.view endEditing:YES];
}
@end