UI里的UIActionSheet按钮
1.效果图:分别为有短信分享 无短信分享

-(void)viewDidLoad{
//添加按钮
UIButton *shareButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 50)];
[shareButton setBackgroundColor:[UIColor redColor]];
[shareButton addTarget:self action:@selector(shareButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:shareButton];
} //点击触发分享按钮
-(void)shareButtonPressed{
[(id)self showActionSheetWeibo:NO];//无短信分享功能 [(id)self showActionSheetWeibo:YES];//有短信分享功能
} - (void)showActionSheetWeibo:(BOOL)ishaveMail { UIActionSheet *actionSheet;
if (ishaveMail == YES) {
actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"分享到新浪微博", @"分享到腾讯微博",@"短信分享", nil];
actionSheet.tag = 99;
}else {
actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"dd" otherButtonTitles:@"分享到新浪微博", @"分享到腾讯微博", nil]; //destructiveButtonTitle被红色高亮显示
actionSheet.tag = 101; }
[actionSheet showFromRect:self.view.bounds inView:self.view animated:YES];
// [actionSheet showInView:self.view]; //显示操作表单
[actionSheet release];
} #pragma mark ActionSheet Delegate Methods
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"clickedButtonAtIndex:%d",buttonIndex);
//其实如果有dextructiveButtonTitle的话,这个所对应的按钮才是编号为0
if (buttonIndex==0) { //新浪微博分享
NSLog(@"新浪微博");
/*点击触发代码*/ }else if(buttonIndex==1) { //腾讯微博分享
NSLog(@"腾讯微博");
/*点击触发代码*/ }else if(actionSheet.tag==99&&buttonIndex==2){
NSLog(@"短信分享"); //发送短信
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://"]]; }
}

2.。直接按钮触发:

通过按键触发buttonPressed - (IBAction)buttonPressed:(id)sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Are you sure?"
delegate:self
cancelButtonTitle:@"No Way!" //取消
destructiveButtonTitle:@"Yes, I’m Sure!" //继续
otherButtonTitles:nil]; //其他按钮,若没则nil
[actionSheet showInView:self.view]; //显示自己 } - (void)actionSheet:(UIActionSheet *)actionSheet
didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex != [actionSheet cancelButtonIndex])
{
NSString *msg = nil; if (nameField.text.length > 0)
msg = [[NSString alloc] initWithFormat:
@"You can breathe easy, %@, everything went OK.",
nameField.text];
else
msg = @"You can breathe easy, everything went OK.";
}
}

自定义ActionSheet:效果图如下:
背景颜色可以自定义,按钮也可以

//点击触发:
-(void)btnPressed{
actionSheet =[[UIActionSheet alloc]initWithTitle:@"\n\n\n\n\n\n\n\n\n\n\n\n\n" //为后面自己增加的view空出空间
delegate:self
cancelButtonTitle:@"cancel"
destructiveButtonTitle:nil
otherButtonTitles:nil];
// [actionSheet addButtonWithTitle:@"登陆注册"];
// [actionSheet addButtonWithTitle:@"手机快速下单"];
// [actionSheet addButtonWithTitle:@"取消"];
[actionSheet showInView:self.view];
// [actionSheet setActionSheetStyle:UIActionSheetStyleBlackOpaque]; UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
view.backgroundColor = [UIColor greenColor];
[actionSheet addSubview:view]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(30, 30, 100, 30);
btn.tag = 1001;
[view addSubview:btn];
[btn addTarget:self action:@selector(exitButtonClick:) forControlEvents:UIControlEventTouchUpInside]; UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn2.frame = CGRectMake(30, 70, 100, 30);
btn2.tag = 1002;
[view addSubview:btn2];
[btn2 addTarget:self action:@selector(exitButtonClick:) forControlEvents:UIControlEventTouchUpInside]; [actionSheet release];
}
//点击自己建按钮触发
-(void)exitButtonClick:(UIButton *)sender{
NSLog(@"%d",sender.tag); [actionSheet dismissWithClickedButtonIndex:sender.tag animated:YES];
}
//点击系统按钮触发
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"click %d",buttonIndex);
} - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
NSLog(@"dismis %d",buttonIndex);
}

UI里的UIActionSheet按钮的更多相关文章
- CRM WebClient UI里的文件是如何上传到Netweaver后台的
使用Chrome开发者工具调试CRM WebClient UI里附件上传的功能: 从本地选择一个文件,断点触发: 前端取得用户选中上传的文件名: Jerry.txt 点Attach按钮后,触发ABAP ...
- iOS开发笔记1:[转]导航栏里的"Back"按钮显示不出来
最近项目中遇到一个问题,push过去的ViewController的Nav上面没有返回按钮,遂搜索资料,找到了以下文档.经测试i,问题解决. 原文地址:http://www.cnblogs.com/s ...
- lhgdialog在打开的窗口里点击按钮关闭当前窗口
lhgdialog在打开的窗口里点击按钮关闭当前窗口 var api = frameElement.api, W = api.opener; api.close();
- 如何在SAP CRM WebClient UI里创建HANA Live Report
1. 使用业务角色ANALYTICSPRO登录WebClient UI: 2. 点击新建按钮: 为新建的报表分配一个HANA Live Query: 指定Query的参数: 上图WebClient U ...
- 如何在CRM WebClient UI里使用HANA Live Report
1. 使用业务角色ANALYTICSPRO登录SAP CRM WebClient UI: 点击新建按钮创建一个新的HANA live report: 类型选择SHL: 弹出窗口,维护report的名称 ...
- flex 在父窗口监听弹出窗口里的某个按钮被点击
flex 在父窗口监听弹出窗口里的某个按钮被点击 这样可以从子窗口拿回数据在父窗口处理数据,不必再子窗口中处理.在某些情形下省去了不少麻烦. /** * 右键菜单项单击事件 * changed by ...
- amazeui学习笔记--js插件(UI增强2)--按钮交互Button
amazeui学习笔记--js插件(UI增强2)--按钮交互Button 一.总结 1.按钮loading状态: <button type="button" class=&q ...
- easyui datagrid里的toobar按钮隐藏、显示、禁用等方式的实现
easyui datagrid里的toobar按钮隐藏.显示.禁用等方式的实现 //隐藏第一个按钮 $('div.datagrid-toolbar a').eq(0).hide(); //隐藏第一条分 ...
- 使用Bootstrap3和Ladda UI实现的多种按钮“加载中”效果体验
在线演示 在线演示 大家在开发基于web的网站或者web应用中,常常在AJAX调用的过程中需要提示用户并且展示相关的“加载中”效果,类似的UI设计也非常多,比如,当点击一个按钮后,在它的旁边显示一个 ...
随机推荐
- Java提高篇——通过分析 JDK 源代码研究 Hash 存储机制
HashMap 和 HashSet 是 Java Collection Framework 的两个重要成员,其中 HashMap 是 Map 接口的常用实现类,HashSet 是 Set 接口的常用实 ...
- ubuntu 16.04 忘记root密码的处理方法
1.开机按ESC,出现如下界面 2.按回车键进入如下界面,然后选中有recovery mode的选项 3.按e进入如下界面,并找到图中红色框的recovery nomodeset,并在这一行的后面输入 ...
- VC6在win7环境下无法添加以及打开现有文件的解决办法
在VC6.0中使用键盘快捷键或者是文件菜单打开现有文件以及添加文件出现编辑器停止响应,弹出内容为Microsoft(R) Developer Studio已停止工作 Windows正在检查解决该 ...
- IE8下JQuery clone 出的select元素使用append添加option异常解决记录
遇到一个怪现象,由于配置参数是多实例的, 故采用JQuery对模板HTML代码进行clone, HTML代码中包括select标签, 在克隆之后需要对select进行添加option. 在firefo ...
- JAVA线程池原理详解二
Executor框架的两级调度模型 在HotSpot VM的模型中,JAVA线程被一对一映射为本地操作系统线程.JAVA线程启动时会创建一个本地操作系统线程,当JAVA线程终止时,对应的操作系统线程也 ...
- 原生的on事件代理
<script> // jQuery $('.el').on('event', function() { }); // 原生方法 [].forEach.call(document.quer ...
- 如何写出优雅的Python之设置class缺省值
今天有个需求时需要为某个类设置缺省值 最开始的代码如下: Class myClass def __init__(self,datalen=None,times=None): if datalen == ...
- 移动前端中viewport(视口) 转
移动前端中常说的 viewport (视口)就是浏览器显示页面内容的屏幕区域.其中涉及几个重要概念是 dpi ( device-independent pixel 设备逻辑像素 )和 CSS 像素之间 ...
- bitcask
Bitcask模型是一种日志型kv模型.所谓日志型,是指它不直接支持随机写入,而是像日志一样支持追加操作.Bitcask模型将随机写入转化为顺序写入. 任意时刻,系统中只有一个数据文件支持写入,称为a ...
- :selected
描述: 查找所有选中的选项元素 HTML 代码: <select> <option value="1">Flowers</option> < ...