日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS UI基础-6.0 UIActionSheet的使用

發布時間:2025/5/22 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS UI基础-6.0 UIActionSheet的使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

UIActionSheet是在iOS彈出的選擇按鈕項,可以添加多項,并為每項添加點擊事件.

使用

1.需要實現UIActionSheetDelegate ?協議

@interface NJWisdomCardDetailViewController ()<UIActionSheetDelegate>@end

2.彈出選擇按鈕框

- (void)showSheet{UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"title,nil時不顯示"delegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:@"確定"otherButtonTitles:@"第一項", @"第二項",nil];actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;[actionSheet showInView:self.view]; }

參數解釋:?

  • actionSheet.actionSheetStyle?=?UIActionSheetStyleBlackOpaque;//設置樣式
  • cancelButtonTitle和destructiveButtonTitle 是系統帶的兩個按鈕。
  • otherButtonTitles是自己定義的項,注意,最后一個參數要是nil。
  • [actionSheet?showInView:self.view]; 這行語句的意思是在當前view顯示Action sheet。

設置樣式,操作表單也支持三種風格:

  • UIActionSheetStyleDefault? ? ? ? ? ? ??//默認風格:灰色背景上顯示白色文字? ?
  • UIActionSheetStyleBlackTranslucent ? ??//透明黑色背景,白色文字? ?
  • UIActionSheetStyleBlackOpaque? ? ? ? ??//純黑背景,白色文字??

3.監聽項的點擊事件。實現協議里的有相應的方法

(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {if (buttonIndex == 0) {[self showAlert:@"確定"];}else if (buttonIndex == 1) {[self showAlert:@"第一項"];}else if(buttonIndex == 2) {[self showAlert:@"第二項"];}else if(buttonIndex == 3) {[self showAlert:@"取消"];} } - (void)actionSheetCancel:(UIActionSheet *)actionSheet{ } -(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{ } -(void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex{ }

注意事項

在開發過程中,發現有時候UIActionSheet的最后一項點擊失效,點最后一項的上半區域時有效,這是在特定情況下才會發生,這個場景就是試用了UITabBar的時候才有。解決辦法:

在showView時這樣使用,[actionSheet showInView:[UIApplication sharedApplication].keyWindow];或者[sheet showInView:[AppDelegate sharedDelegate].tabBarController.view];這樣就不會發生遮擋現象了。

?

總結

以上是生活随笔為你收集整理的iOS UI基础-6.0 UIActionSheet的使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。