Swift5.2 Control MenuView(菜单弹窗) 📅 发布时间:2026/8/20 15:08:49 👁 浏览次数: 一直觉得自己写的不是技术而是情怀一个个的教程是自己这一路走来的痕迹。靠专业技能的成功是最具可复制性的希望我的这条路能让你们少走弯路希望我能帮你们抹去知识的蒙尘希望我能帮你们理清知识的脉络希望未来技术之巅上有你们也有我。Swift-MenuView(弹窗)下载代码效果展示代码使用代码importUIKitclassViewController:UIViewController{letbtnUIButton(frame:CGRect(x:150,y:150,width:60,height:30))letchooseViewChooseCategroyView()letnameList[全乎分类,禽兽肉类,田园蔬菜,菌菇水生,根茎瓜菇];overridefuncviewDidLoad(){super.viewDidLoad()view.backgroundColorUIColor.white//传递数据chooseView.classesnameList chooseView.dataSourceselfview.addSubview(btn)btn.titleLabel?.textColorUIColor.blue btn.titleLabel?.fontUIFont.systemFont(ofSize:14)btn.backgroundColorUIColor.orange btn.setTitle(菜单,for:.normal)btn.add(for:.touchUpInside){[self]in//获取btn相对window的参考点letrectbtn.convert(btn.bounds,to:SPKeyWindow)//设置顶部距离chooseView.layoutToprect.origin.yrect.height5//设置左边距离chooseView.layoutLeftrect.origin.x//设置宽度chooseView.layoutWidth100//显示viewchooseView.show()}}}extensionViewController:ChooseCategroyViewDataSource{//返回点击对应的行funcchooseCategroyView(view:ChooseCategroyView,select classModel:String,indexPath:IndexPath){print(indexPath \(indexPath.item))}}