iOS UI基础-6.0 UIActionSheet的使用
生活随笔
收集整理的這篇文章主要介紹了
iOS UI基础-6.0 UIActionSheet的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
UIActionSheet是在iOS彈出的選擇按鈕項,可以添加多項,并為每項添加點擊事件.
使用
1.需要實現UIActionSheetDelegate ?協議
@interface NJWisdomCardDetailViewController ()<UIActionSheetDelegate>@end2.彈出選擇按鈕框
- (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的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: js setTimeout()的使用
- 下一篇: uploadify控制 上传图片到百度