当前位置: 移动技术网 > 移动技术>移动开发>IOS > iOS中UIActionSheet动态添加按钮

iOS中UIActionSheet动态添加按钮

2019年07月24日  | 移动技术网移动技术  | 我要评论

一,效果图。

二,代码。

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动态添加按钮,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网