- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self UIActionSheetButton];
[self AlertViewButton];
}
#pragma mark - UIActionSheet
- (void)UIActionSheetButton
{
/* 创建一个 button */
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(40, 60, 300, 40);
button.backgroundColor = [UIColor cyanColor];
[button setTitle:@"UIActionSheet 效果" forState:UIControlStateNormal];
[self.view addSubview:button];
/* 添加点击事件 */
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)buttonClicked:(UIButton *)button
{
/* UIActionSheet
* initWithTitle: 设置标题, 将会显示在 ActionSheet 的顶部
* delegate: 设置 ActionSheet 的一个按钮被按下后, 它的 delegate 将会被通知, 并且这个 delegate 的 actionSheet : didDismissWithButtonIndex 方法将会执行.
* cancelButtonTitle: 设置取消按钮的标题, 这个按钮将会显示在最下面
* destructiveButtonTitle: 设置第一个确定按钮的标题, 这个按钮可以理解成"好的, 继续"
* otherButtonTitles: 可以设置任意多的确定按钮
*/
UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"你喜欢我吗?" delegate:self cancelButtonTitle:@"不是不是的" destructiveButtonTitle:@"是的, 我喜欢你啊!" otherButtonTitles:@"", nil];
[action showInView:self.view];
}
#pragma mark - AlertView
- (void)AlertViewButton
{
/* 创建 button 对象 */
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(40, 120, 300, 40);
button.backgroundColor = [UIColor cyanColor];
[button setTitle:@"UIAlertView 效果" forState:UIControlStateNormal];
[self.view addSubview:button];
/* 添加点击事件 */
[button addTarget:self action:@selector(button1Clicked:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)button1Clicked:(UIButton *)button1Clicked
{
/* UIAlertView
* initWithTitle: 设置标题, 将会显示在 Alert 的顶部
* message: 设置提示消息内容
* delegate: 设置 Alert 的委托, 这里设为 self
* cancelButtonTitle: 设置取消按钮的标题
* otherButtonTitles: 设置多个按钮
*/
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"完美告白" message:@"我喜欢你呀" delegate:self cancelButtonTitle:@"好的" otherButtonTitles: nil];
[alert show];
}
# pragma mark - UIAlertView 和 UIActionSheet 的不同
/* Alert 相当于 Windows 中的 Messagebox , 跟 Action Sheet 也是类似. 不同的是, Alert可以只有一个选择项, 而 Action Sheet 却至少要两个选项 */
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self UIActionSheetButton];
[self AlertViewButton];
}
#pragma mark - UIActionSheet
- (void)UIActionSheetButton
{
/* 创建一个 button */
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(40, 60, 300, 40);
button.backgroundColor = [UIColor cyanColor];
[button setTitle:@"UIActionSheet 效果" forState:UIControlStateNormal];
[self.view addSubview:button];
/* 添加点击事件 */
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)buttonClicked:(UIButton *)button
{
/* UIActionSheet
* initWithTitle: 设置标题, 将会显示在 ActionSheet 的顶部
* delegate: 设置 ActionSheet 的一个按钮被按下后, 它的 delegate 将会被通知, 并且这个 delegate 的 actionSheet : didDismissWithButtonIndex 方法将会执行.
* cancelButtonTitle: 设置取消按钮的标题, 这个按钮将会显示在最下面
* destructiveButtonTitle: 设置第一个确定按钮的标题, 这个按钮可以理解成"好的, 继续"
* otherButtonTitles: 可以设置任意多的确定按钮
*/
UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"你喜欢我吗?" delegate:self cancelButtonTitle:@"不是不是的" destructiveButtonTitle:@"是的, 我喜欢你啊!" otherButtonTitles:@"", nil];
[action showInView:self.view];
}
#pragma mark - AlertView
- (void)AlertViewButton
{
/* 创建 button 对象 */
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(40, 120, 300, 40);
button.backgroundColor = [UIColor cyanColor];
[button setTitle:@"UIAlertView 效果" forState:UIControlStateNormal];
[self.view addSubview:button];
/* 添加点击事件 */
[button addTarget:self action:@selector(button1Clicked:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)button1Clicked:(UIButton *)button1Clicked
{
/* UIAlertView
* initWithTitle: 设置标题, 将会显示在 Alert 的顶部
* message: 设置提示消息内容
* delegate: 设置 Alert 的委托, 这里设为 self
* cancelButtonTitle: 设置取消按钮的标题
* otherButtonTitles: 设置多个按钮
*/
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"完美告白" message:@"我喜欢你呀" delegate:self cancelButtonTitle:@"好的" otherButtonTitles: nil];
[alert show];
}
# pragma mark - UIAlertView 和 UIActionSheet 的不同
/* Alert 相当于 Windows 中的 Messagebox , 跟 Action Sheet 也是类似. 不同的是, Alert可以只有一个选择项, 而 Action Sheet 却至少要两个选项 */