UIKit 框架之UIActionSheet
生活随笔
收集整理的這篇文章主要介紹了
UIKit 框架之UIActionSheet
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
UIAlertView和UIActionSheet相似,區別很小, 很容易理解。
?
// // ViewController.m // UIActionSheet // // Created by City--Online on 15/5/18. // Copyright (c) 2015年 XQB. All rights reserved. //#import "ViewController.h"@interface ViewController ()<UIActionSheetDelegate> @property(nonatomic,strong) UIActionSheet *actionSheet; @property(nonatomic,strong) UIActionSheet *actionSheet1; @end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];//設置Frame無效_actionSheet=[[UIActionSheet alloc]initWithFrame:CGRectMake(20, 20, 200, 100)];[_actionSheet addButtonWithTitle:@"相冊"];[_actionSheet addButtonWithTitle:@"相機"];[_actionSheet addButtonWithTitle:@"取消"];_actionSheet.cancelButtonIndex=2;_actionSheet.destructiveButtonIndex=1;_actionSheet.title=@"提示";_actionSheet.delegate=self; // typedef NS_ENUM(NSInteger, UIActionSheetStyle) { // UIActionSheetStyleAutomatic = -1, // take appearance from toolbar style otherwise uses 'default' // UIActionSheetStyleDefault = UIBarStyleDefault, // UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent, // UIActionSheetStyleBlackOpaque = UIBarStyleBlackOpaque, // };_actionSheet.actionSheetStyle=UIActionSheetStyleBlackOpaque;_actionSheet.tag=10001;NSLog(@"firstOtherButtonIndex=%ld",_actionSheet.firstOtherButtonIndex);for (int i=0; i<_actionSheet.numberOfButtons; i++) {NSLog(@"i=%d %@",i,[_actionSheet buttonTitleAtIndex:i]);}[_actionSheet showInView:self.view];_actionSheet1 =[[UIActionSheet alloc]initWithTitle:@"提示" delegate:self cancelButtonTitle:@"NO" destructiveButtonTitle:@"DestructiveButton" otherButtonTitles:@"YES", nil];_actionSheet1.tag=10002;for (int i=0; i<_actionSheet1.numberOfButtons; i++) {NSLog(@"i=%d %@",i,[_actionSheet1 buttonTitleAtIndex:i]);}[_actionSheet1 showInView:self.view];} //UIActionSheetDelegate - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {if (actionSheet.tag==10001) {NSString *title=[_actionSheet buttonTitleAtIndex:buttonIndex];NSLog(@"我點擊了: %@",title);}else{if (buttonIndex==2) {[_actionSheet dismissWithClickedButtonIndex:2 animated:YES];}} }//以下這些和UIAlertView的相似 - (void)actionSheetCancel:(UIActionSheet *)actionSheet {NSLog(@"actionSheetCancel"); }- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {NSLog(@"willPresentActionSheet"); } - (void)didPresentActionSheet:(UIActionSheet *)actionSheet {NSLog(@"didPresentActionSheet"); }- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex {NSLog(@"willDismissWithButtonIndex"); } - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {NSLog(@"didDismissWithButtonIndex"); } - (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated. }@end?
轉載于:https://www.cnblogs.com/5ishare/p/4512237.html
總結
以上是生活随笔為你收集整理的UIKit 框架之UIActionSheet的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【一个iOS官方文档错误】关于keyWi
- 下一篇: 功能测试工具Selenium IDE