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按钮的更多相关文章

  1. CRM WebClient UI里的文件是如何上传到Netweaver后台的

    使用Chrome开发者工具调试CRM WebClient UI里附件上传的功能: 从本地选择一个文件,断点触发: 前端取得用户选中上传的文件名: Jerry.txt 点Attach按钮后,触发ABAP ...

  2. iOS开发笔记1:[转]导航栏里的"Back"按钮显示不出来

    最近项目中遇到一个问题,push过去的ViewController的Nav上面没有返回按钮,遂搜索资料,找到了以下文档.经测试i,问题解决. 原文地址:http://www.cnblogs.com/s ...

  3. lhgdialog在打开的窗口里点击按钮关闭当前窗口

    lhgdialog在打开的窗口里点击按钮关闭当前窗口 var api = frameElement.api, W = api.opener; api.close();

  4. 如何在SAP CRM WebClient UI里创建HANA Live Report

    1. 使用业务角色ANALYTICSPRO登录WebClient UI: 2. 点击新建按钮: 为新建的报表分配一个HANA Live Query: 指定Query的参数: 上图WebClient U ...

  5. 如何在CRM WebClient UI里使用HANA Live Report

    1. 使用业务角色ANALYTICSPRO登录SAP CRM WebClient UI: 点击新建按钮创建一个新的HANA live report: 类型选择SHL: 弹出窗口,维护report的名称 ...

  6. flex 在父窗口监听弹出窗口里的某个按钮被点击

    flex 在父窗口监听弹出窗口里的某个按钮被点击 这样可以从子窗口拿回数据在父窗口处理数据,不必再子窗口中处理.在某些情形下省去了不少麻烦. /** * 右键菜单项单击事件 * changed by ...

  7. amazeui学习笔记--js插件(UI增强2)--按钮交互Button

    amazeui学习笔记--js插件(UI增强2)--按钮交互Button 一.总结 1.按钮loading状态: <button type="button" class=&q ...

  8. easyui datagrid里的toobar按钮隐藏、显示、禁用等方式的实现

    easyui datagrid里的toobar按钮隐藏.显示.禁用等方式的实现 //隐藏第一个按钮 $('div.datagrid-toolbar a').eq(0).hide(); //隐藏第一条分 ...

  9. 使用Bootstrap3和Ladda UI实现的多种按钮“加载中”效果体验

    在线演示 在线演示 大家在开发基于web的网站或者web应用中,常常在AJAX调用的过程中需要提示用户并且展示相关的“加载中”效果,类似的UI设计也非常多,比如,当点击一个按钮后,在它的旁边显示一个 ...

随机推荐

  1. RabbitMQ学习总结 第三篇:工作队列Work Queue

    目录 RabbitMQ学习总结 第一篇:理论篇 RabbitMQ学习总结 第二篇:快速入门HelloWorld RabbitMQ学习总结 第三篇:工作队列Work Queue RabbitMQ学习总结 ...

  2. EF 之 MVC 排序,查询,分页 Sorting, Filtering, and Paging For MVC About EF

    最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精    上篇博客我们学习了EF CodeFirst增删改查 ...

  3. Thinkphp---------Call to a member function free_result() on a non-object

    1.平时用框架用久了,直接执行原生的sql反而做起来反应迟钝了.今天遇到一个问题,就是直接执行一个添加的sql语句,然后我用了TP框架的M()->query();方法.运行以后,会报Call t ...

  4. Android之下载管理者

    public interface HttpDownloader { public void setDownloadManager(HttpDownloadManager manager); publi ...

  5. 【转】PowerShell入门(六):远程操作

    转至:http://www.cnblogs.com/ceachy/archive/2013/02/20/PowerShell_Remoting.html PowerShell远程操作是远程管理的基础, ...

  6. 【转】PowerShell入门(一):PowerShell能干什么?

    转至:http://www.cnblogs.com/ceachy/archive/2013/01/30/WhatCanPowerShellDo.html PowerShell能干什么呢?就像序言中提到 ...

  7. WebClient与WebRequest差异

    WebRequst的使用 WebClient和HttpWebRequst是用来获取数据的2种方式,在我的这篇数据访问(2)中主要是讲的WebClient的使用,一般而言,WebClient更倾向于“按 ...

  8. 2015弱校联盟(1) - I. Travel

    I. Travel Time Limit: 3000ms Memory Limit: 65536KB The country frog lives in has n towns which are c ...

  9. mac上安装opencv3

    转载于:http://blog.csdn.net/sanwandoujiang/article/details/51159983 在macosx上安装opencv2 brew tap homebrew ...

  10. Android Fragment 真正的完全解析(上)

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/37970961 自从Fragment出现,曾经有段时间,感觉大家谈什么都能跟Fra ...