UI5_UIAlertView与UIActionSheet
2015-07-11 15:50
330 查看
// // ViewController.h // UI5_UIAlertView与UIActionSheet // // Created by zhangxueming on 15/7/7. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController <UIAlertViewDelegate,UIActionSheetDelegate> @end // // ViewController.m // UI5_UIAlertView与UIActionSheet // // Created by zhangxueming on 15/7/7. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSArray *titles =@[@"alert", @"action"]; for (int i=0; i<2; i++) { UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(100, 200+i*100, self.view.frame.size.width-200,50); [btn setTitle:titles[i] forState:UIControlStateNormal]; [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside]; btn.titleLabel.font = [UIFont boldSystemFontOfSize:24]; btn.tag= 100+i; [self.view addSubview:btn]; } } - (void)btnClicked:(UIButton *)btn { if (btn.tag==100) { //alert UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"余额不足" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",@"充值", nil]; [alert show]; } else if (btn.tag == 101) { UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"分享" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"新浪微博" otherButtonTitles:@"QQ",@"微信",@"陌陌", nil]; [sheet showInView:self.view]; } } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { NSLog(@"index = %li", buttonIndex); } - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { NSLog(@"index = %li", buttonIndex); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- UI4_UIStepper与UIProgressView
- UI2_UISwitch与UIActivity
- Implement Queue using Stacks(用栈实现队列)
- NGUI 图片变灰
- UI1_UISlider与UISegment
- UI5_UINavigation传值
- UI4_UIToolBar
- (七十一)关于UITableView退出崩溃的问题和滚动到底部的方法
- (七十一)关于UITableView退出崩溃的问题和滚动到底部的方法
- UI3_UIbarButtonItem
- PHP include语句和require语句
- UI2_UINavigationBar
- UI1_UINavigationController
- 实现UILabel高度和宽度的自适应和UITextView的高度自适应
- UI5_HomeWorkCompanyViewController
- 【七】注入框架RoboGuice使用:(Your First Custom Binding)
- UI4_注册登录界面
- UI3_视图切换
- UI2_视图切换ViewController
- UI_UITableView编辑