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. 菜菜CPP日记

    分支预测建议: http://www.cppblog.com/mysileng/archive/2014/09/29/208454.html #ifndef likely #define likely ...

  2. 开源实体映射框架EmitMapper介绍

    开源实体映射框架EmitMapper介绍   综述       EmitMapper是一个开源实体映射框架,地址:http://emitmapper.codeplex.com/.       Emit ...

  3. soap和http的区别

    Http get,post,soap协议都是在http上运行的1)get:请求参数是作为一个key/value对的序列(查询字符串)附加到URL上的查询字符串的长度受到web浏览器和web服务器的限制 ...

  4. 响应式布局2--MATE

    随着高端手机(Andriod,Iphone,Ipod,WinPhone等)的盛行,移动互联应用开发也越来越受到人们的重视,用html5开发移动应用是最好的选择.然而,每一款手机有不同的分辨率,不同屏幕 ...

  5. Linux开机流程

    在开机时,由于80x86的特性CS(Code Segment)这个寄存器中放的都是1,而IP(Instruction Pointer)这个寄存器中全部放着0,换句话说,CS=FFFF而IP=0000. ...

  6. xcode编译错误

    1.xcode无效文件的编译错误. 问题: clang: error: no such file or directory: '/Users/admin/client/trunk/sengoku_sc ...

  7. 02-FPGA设计流程介绍——小梅哥FPGA设计思想与验证方法视频教程配套文档

    芯航线——普利斯队长精心奉献 课程目标: 1.了解并学会FPGA开发设计的整体流程 2.设计一个二选一选择器并进行功能仿真.时序仿真以及板级验证 实验平台:芯航线FPGA开发板.杜邦线 实验内容: 良 ...

  8. c++中endl的函义

    c++中endl的函义是回车的函义,Enter

  9. jquery判断id是否存在

    1.判断标签是否存在 ){ 存在 } 2.判断(id="id名"的标签)是否存在,下面的不可以!!!因为 $("#id") 不管对象是否存在都会返回 objec ...

  10. SUDTOJ 3323园艺问题 (线段树)

    园艺问题 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 本巨养了一盆双色茉莉.这种花有一种特点:第i朵花在第Di天盛开,刚开时是紫色的 ...