IOS学习1 动态添加Button
2012-05-29 10:03
387 查看
动态添加Button的效果就是点击之后,生成一个按钮,并为按钮添加点击的方法。
1、在xib文件上拖拽添加一个button,标题为:添加button。
2、按住ctrl键拖拽到addbuttonViewController.m文件空白处,生成IBAction,填充代码后如下:
3、动态生成的button点击事件方法:
生成的button点击弹出提示框。
4、编译运行效果 图1 2 3:
图1:
点击按钮后
图2:
图3:
程序源码下载:gitbub: https://github.com/schelling/YcDemo/tree/master/DynamicAddButton1
csdn资源:http://download.csdn.net/detail/totogo2010/4336287
1、在xib文件上拖拽添加一个button,标题为:添加button。
2、按住ctrl键拖拽到addbuttonViewController.m文件空白处,生成IBAction,填充代码后如下:
- (IBAction)addButton:(id)sender { CGRect frame = CGRectMake(90, 200, 200, 60); UIButton *someAddButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; someAddButton.backgroundColor = [UIColor clearColor]; [someAddButton setTitle:@"动态添加一个按钮!" forState:UIControlStateNormal]; someAddButton.frame = frame; [someAddButton addTarget:self action:@selector(someButtonClicked) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:someAddButton]; }
3、动态生成的button点击事件方法:
生成的button点击弹出提示框。
-(void) someButtonClicked{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您点击了动态按钮!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; }
4、编译运行效果 图1 2 3:
图1:
点击按钮后
图2:
图3:
程序源码下载:gitbub: https://github.com/schelling/YcDemo/tree/master/DynamicAddButton1
csdn资源:http://download.csdn.net/detail/totogo2010/4336287
相关文章推荐
- iOS学习之动态添加Button和监听UIAlertView按钮
- iOS学习之动态添加Button和监听UIAlertView按钮
- iOS学习基础学习之动态添加Button和监听UIAlertView按钮
- IOS学习之动态添加Button和监听UIAlertView按钮
- iOS学习之动态添加Button和监听UIAlertView按钮
- IOS学习之动态添加Button和监听UIAlertView按钮
- iOS学习之动态添加Button和监听UIAlertView按钮
- iOS学习之动态添加Button和监听UIAlertView按钮
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
- QT学习:根据数据库的内容动态添加Button
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
- ios开发runtime学习四:动态添加属性
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
- IOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
- (转)IOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem