动态添加Button的效果就是点击之后,生成一个按钮,并为按钮添加点击的方法。

1、在xib文件上拖拽添加一个button,标题为:添加button。

IOS学习1 动态添加ButtonIOS学习1 动态添加Button

IOS学习1 动态添加Button


2、按住ctrl键拖拽到addbuttonViewController.m文件空白处,生成IBAction,填充代码后如下:


3、动态生成的button点击事件方法:

生成的button点击弹出提示框。


4、编译运行效果 图1 2 3:

图1:

IOS学习1 动态添加Button

IOS学习1 动态添加ButtonIOS学习1 动态添加Button


点击按钮后

图2:

IOS学习1 动态添加Button

IOS学习1 动态添加Button

IOS学习1 动态添加Button


图3:IOS学习1 动态添加Button

IOS学习1 动态添加Button

IOS学习1 动态添加Button

IOS学习1 动态添加Button



程序源码下载:gitbub:  https://github.com/schelling/YcDemo/tree/master/DynamicAddButton1

                            csdn资源:http://download.csdn.net/detail/totogo2010/4336287


相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
  • 2021-10-27
  • 2021-12-16
  • 2021-04-09
猜你喜欢
  • 2021-12-15
  • 2021-10-10
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案