欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS中UIActionSheet动态添加按钮

程序员文章站 2023-12-22 08:36:10
一,效果图。 二,代码。 rootviewcontroller.h #import @interface r...

一,效果图。

iOS中UIActionSheet动态添加按钮

二,代码。

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

上一篇:

下一篇: