iOS中有两个弹出视图的控件,分别是UIActionSheet和UIAlterView.效果图如下:
主要代码如下:
1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 // Do any additional setup after loading the view, typically from a nib. 4 UIButton * button1 = [UIButton buttonWithType:UIButtonTypeCustom]; 5 button1.frame = CGRectMake(100, 100, 100, 50); 6 button1.backgroundColor = [UIColor cyanColor]; 7 [button1 addTarget:self action:@selector(onclick1:) forControlEvents:UIControlEventTouchUpInside]; 8 [self.view addSubview:button1]; 9 10 UIButton * button2 = [UIButton buttonWithType:UIButtonTypeCustom]; 11 button2.frame = CGRectMake(100 , 200, 100, 50); 12 button2.backgroundColor = [UIColor redColor]; 13 [button2 addTarget:self action:@selector(onclick2:) forControlEvents:UIControlEventTouchUpInside]; 14 [self.view addSubview:button2]; 15 } 16 -(void)onclick1:(UIButton *)btn{ 17 UIActionSheet * actionsheet = [[UIActionSheet alloc]initWithTitle:@"提示信息" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确认" otherButtonTitles:nil]; 18 [actionsheet showInView:self.view]; 19 } 20 -(void)onclick2:(UIButton *)btn{ 21 UIAlertView * alterView = [[UIAlertView alloc]initWithTitle:@"警告" message:@"您的言论违法中华人民共和国法律,有可能查你水表" delegate:self cancelButtonTitle:@"继续发表" otherButtonTitles:nil]; 22 [alterView show]; 23 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探