一,效果圖。
二,代碼。
RootViewController.h
#import <UIKit/UIKit.h>@interface RootViewController : UIViewController<UIActionSheetDelegate>@end
RootViewController.m
//點擊任何處,彈出UIActionSheet-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UIActionSheet *sheet=[[UIActionSheet alloc]initWithTitle:@"標題" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil, nil]; // 逐個添加按鈕(比如可以是數組循環) [sheet addButtonWithTitle:@"Item A"]; [sheet addButtonWithTitle:@"Item B"]; [sheet addButtonWithTitle:@"Item C"]; // 同時添加一個取消按鈕 [sheet addButtonWithTitle:@"Cancel"]; sheet.cancelButtonIndex = sheet.numberOfButtons-1; [sheet showInView:self.view];}
以上所述是小編給大家介紹的iOS中UIActionSheet動態添加按鈕,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答