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. linux下对date和timestamp的互转

    1. date 到 timestamp: $ date -d '2009-12-01 23:20' +%s 12596808002. timestamp 到 date$ date -d '1970-0 ...

  2. 与子域名共用session信息

    参考自 http://www.jb51.net/article/19664.htm 下面的步骤只使用于两个域名在同一个服务起得情况下,如果不在一个服务器上,就需要考虑通过数据库来存储session信息 ...

  3. (copy) Shell Script to Check Linux System Health

    source: http://linoxide.com/linux-shell-script/shell-script-check-linux-system-health/ This article ...

  4. 在UIScrollView的delegate方法判断滚动快慢

    // 这里做预加载 CGPoint currentOffset = scrollView.contentOffset; NSTimeInterval currentTime = [NSDate tim ...

  5. EBS创建相应的用户

    登陆EBS,依次点击"System Administrator"-->"Security"-->"User"-->&quo ...

  6. 20145320《Java程序设计》第五次实验报告

    20145320<Java程序设计>第五次实验报告 北京电子科技学院(BESTI)实验报告 课程:Java程序设计 班级:1453 指导教师:娄嘉鹏 实验日期:2016.05.06 18: ...

  7. boost源码剖析----boost::any

    boost源码剖析----boost::any 有的时候我们需要有一个万能类型来进行一些操作,这时候boost::any就派上用场了. boost::Any testInt(10); int val ...

  8. Failed to execute request because the App-Domain could not be created.

    原错误信息: 服务器应用程序不可用 您试图在此 Web 服务器上访问的 Web 应用程序当前不可用.请点击 Web 浏览器中的“刷新”按钮重试您的请求. 管理员注意事项: 详述此特定请求失败原因的错误 ...

  9. tomcat部署https

    在server.xml配置文件中增加证书位置跟密码: <Connector port="443" protocol="org.apache.coyote.http1 ...

  10. caffe问题集锦

    不断更新中... 1.问题:check failure stack trace:*** 解决方法:路径错误,重新去看自己的路径是否有错误 2.Check failed: error == cudaSu ...