一,效果图。

【代码笔记】iOS-UIActionSheet动态添加按钮

二,代码。

RootViewController.h

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController
<UIActionSheetDelegate>

@end

 

RootViewController.m

【代码笔记】iOS-UIActionSheet动态添加按钮
//点击任何处,弹出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动态添加按钮

相关文章:

  • 2021-06-16
  • 2021-12-05
  • 2019-07-30
  • 2021-12-19
  • 2021-07-12
  • 2021-11-23
  • 2021-08-27
  • 2021-12-20
猜你喜欢
  • 2022-01-15
  • 2021-04-26
  • 2021-11-29
  • 2021-12-27
  • 2021-05-05
  • 2021-04-08
  • 2021-11-08
相关资源
相似解决方案