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. ionic cordova 热更新

    因为项目需要,使用cordova的热更新插件,本地调试很简单,看连接https://github.com/nordnet/cordova-hot-code-push,就几步,这里不说了. 下面两个要装 ...

  2. 对于字符串拼接,string.format、stringbuilder、+=

    sring拼接经常会用到,拼接时候使用的方法,每个人的又不一样,有的是不知道哪个效率高,也有一些是为了方便不差那么一点时间! 今天百度查了查他们的区别! += 是效率最低的一个,尽量避免使用,当然,不 ...

  3. JavaScript实现绑定DOM的定时器插件

    问题 使用原生的setTimeout和setInterval仅仅能够实现, 定时执行事件处理函数, 在网页开发中, 往往会出现一种情况,定时器用于定时更新某个页面区域的数据, 往往在页面加载之后, 就 ...

  4. impdp报错: ORA-39064: 无法写入日志文件 ORA-29285: 文件写入错误

    windows平台下,oracle 11.2.0.1在使用impdp向测试环境导入数据的时候,报出如下错误: 错误原因: 数据泵在写日志文件的时候,使用的是数据库字符集.如果客户端的环境变量NLS_L ...

  5. 更新数据前jquery如何填充数据到表单域中

    $("#p_city option[value='${project.city}']").attr("selected","selected" ...

  6. html drag 拖拽用法和注意事项

    1.拖拽过程中的事件暂时jQuery里还没有,只能通过html DOM 来进行绑定,不然无法获取dataTransfer对象 2.在dragstart .dragover 等事件中可以用 evt.pr ...

  7. SQL2005中的事务与锁定(五)- 转载

    ------------------------------------------------------------------------ -- Author : HappyFlyStone - ...

  8. 【转】PowerShell入门(八):函数、脚本、作用域

    转至:http://www.cnblogs.com/ceachy/archive/2013/02/26/PoweShell_Function_Script_Scope.html 脚本所体现的是Powe ...

  9. Android 开机启动

    创建一个Receiver,用来监听开机完毕: public class MyReceiver extends BroadcastReceiver { static final String actio ...

  10. Iptables防火墙

    1 位置 使用vim /usr/sysconfig/iptables 2 启动.关闭.保存 service iptables stop service iptables start service i ...