iOS开发:关于ActionSheet

移动开发 iOS
本文介绍了iOS开发中的关于ActionSheet的功能与用法,希望本文对正在学习或者是准备要开始学习iOS开发的同学起到一些作用。

显示菜单的方法:

1、showInView

2、showFromToolBar:和showFromTabBar

视图控制类需要是现实协议接口UIActionSheetDelegate

  1. @interface HelloController :UIViewController<UIActionSheetDelegate> 
  2. @end 

主要实现代码:

  1. - (void)actionSheet:(UIActionSheet*)actionSheetclickedButtonAtIndex:(NSInteger)buttonIndex 
  2. printf("User Pressed Button %d\n",buttonIndex + 1); 
  3. [actionSheet release]; 
  4. - (void) presentSheet 
  5. UIActionSheet *menu = [[UIActionSheetalloc] 
  6. initWithTitle: @"FileManagement" 
  7. delegate:self 
  8. cancelButtonTitle:@"Cancel" 
  9. destructiveButtonTitle:@"DeleteFile" 
  10. otherButtonTitles:@"Rename File", @"EmailFile", nil]; 
  11. [menu showInView:self.view]; 
  12. }

类学习

UIActionSheet类

继承UIView

Use the UIActionSheet class to presentthe user with a set of alternatives for how to proceed with a giventask. You can also use action sheets to prompt the user to confirma potentially dangerous action. The action sheet contains anoptional title and one or more buttons, each of which correspondsto an action to take. 

使用UIActionSheet类呈现给用户一系列交替选项用于决定如何处理所给的任务。你也可以使用动作表来提示用户确认具有潜在危险的动作。动作表包含可选标题和1个或多个按钮,每个按钮对应响应所给的动作。

Creating Action Sheets

  1. –initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles: 

Setting Properties

  1. delegate  property 
  2. title  property 
  3. visible  property 
  4. actionSheetStyle property 

Configuring Buttons

  1. –addButtonWithTitle: 
  2. numberOfButtons property 
  3. –buttonTitleAtIndex: 
  4. cancelButtonIndex property 
  5. destructiveButtonIndex property 
  6. firstOtherButtonIndex property 

Presenting the Action Sheet

  1. –showFromTabBar: 
  2. –showFromToolbar: 
  3. –showInView: 
  4. –showFromBarButtonItem:animated: 
  5. –showFromRect:inView:animated: 

Dismissing the Action Sheet

  1. –dismissWithClickedButtonIndex:animated: 

备注:比对学习下UIAlertView,你会发现这两个类基本类似

这里还有一组常量值

UIActionSheetStyle

Specifies the style of an actionsheet.

  1. typedef enum { 
  2. UIActionSheetStyleAutomatic  =-1, 
  3. UIActionSheetStyleDefault  = UIBarStyleDefault, 
  4. UIActionSheetStyleBlackTranslucent =UIBarStyleBlackTranslucent, 
  5. UIActionSheetStyleBlackOpaque  =UIBarStyleBlackOpaque, 
  6. } UIActionSheetStyle; 

Constants

UIActionSheetStyleAutomatic

Takes the appearance of the bottom bar if specified; otherwise,same as UIActionSheetStyleDefault.

UIActionSheetStyleDefault

 Thedefault style.

UIActionSheetStyleBlackTranslucent

 Ablack translucent style.

UIActionSheetStyleBlackOpaque

 Ablack opaque style.

协议接口学习

UIActionSheetDelegate协议接口

The UIActionSheetDelegate protocoldefines the methods a delegate of a UIActionSheet object shouldimplement. The delegate implements the button actions and any othercustom behavior. Some of the methods defined in this protocol areoptional.

Responding to Actions

  1. –actionSheet:clickedButtonAtIndex: 

Customizing Behavior

  1. –willPresentActionSheet: 
  2. –didPresentActionSheet: 
  3. –actionSheet:willDismissWithButtonIndex: 
  4. –actionSheet:didDismissWithButtonIndex: 

Canceling

  1. –actionSheetCancel: 
责任编辑:闫佳明 来源: blog.sina
相关推荐

2011-05-11 10:02:37

iOS

2015-01-19 12:19:04

iOS源码ActionSheet仿QQ音乐

2014-03-12 10:13:00

iOSSEL对象

2011-08-18 11:19:13

IOS开发Core Plot S

2013-05-02 10:40:24

xcode

2017-11-06 16:00:05

iOS安卓发送原图

2011-08-17 14:32:44

iOS开发绘制

2014-06-10 13:44:58

iOSUIImage知识点

2011-08-09 16:08:58

IOS游戏Cocos2d

2011-08-16 16:14:07

IOS开发HTML5通用接口

2018-11-29 13:50:02

APIAPP数据集

2011-09-02 19:12:59

IOS应用Sqlite数据库

2015-09-10 09:10:46

2016-03-18 09:36:13

ios基础框架

2011-05-11 09:55:18

iOSObjective-C

2014-07-23 13:17:53

iOSUITextField

2017-03-20 15:58:20

iOS开发常用宏

2013-09-12 12:55:53

iOS开发

2015-09-01 10:37:54

ios静态库开发

2013-09-12 15:37:09

iOS开发流程
点赞
收藏

51CTO技术栈公众号