一,效果图。
二,代码。
rootviewcontroller.h
1
2
3
4
|
#import <uikit/uikit.h>
@interface rootviewcontroller : uiviewcontroller
<uiactionsheetdelegate>
@end
|
rootviewcontroller.m
1
2
3
4
5
6
7
8
9
10
11
12
13
|
//点击任何处,弹出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动态添加按钮,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!
原文链接:http://www.cnblogs.com/yang-guang-girl/archive/2017/06/16/7025850.html