iOS: 学习笔记, 动态添加按钮
来源:互联网 发布:网络系统安全技术 编辑:程序博客网 时间:2024/05/16 23:42
1. 新建iOS -> Single View Application.
3. 运行程序.
2. 个性控制器文件YYViewController.m(此处修改为你相应的控制器文件名)
//// YYViewController.m// StudyDynamicButton//// Created by yao_yu on 14-5-27.// Copyright (c) 2014年 yao_yu. All rights reserved.//#import "YYViewController.h"@interface YYViewController ()@end@implementation YYViewController- (void)onAddButtonClicked{ CGRect pframe = self.view.frame; CGFloat width = 200; CGFloat height = 35; CGRect frame = CGRectMake(pframe.origin.x + (pframe.size.width - width)/2, pframe.origin.y + height * 2, width, height); UIButton *btnAddedButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btnAddedButton.backgroundColor = [UIColor clearColor]; [btnAddedButton setTitle:@"动态添加的按钮" forState:UIControlStateNormal]; btnAddedButton.frame = frame; [btnAddedButton addTarget:self action:@selector(onDynamicButtonClicked) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btnAddedButton];}-(void) onDynamicButtonClicked{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您点击了动态按钮" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",@"第二项", nil]; [alert show];}-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSLog(@"按钮索引:%ld", buttonIndex);}- (void)viewDidLoad{ [super viewDidLoad]; //手动添加按钮 CGRect pframe = self.view.frame; CGFloat width = 200; CGFloat height = 35; CGRect frame = CGRectMake(pframe.origin.x + (pframe.size.width - width)/2, pframe.origin.y + height, width, height); UIButton *btnAddDynamicButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btnAddDynamicButton.backgroundColor = [UIColor clearColor]; [btnAddDynamicButton setTitle:@"增加动态按钮" forState:UIControlStateNormal]; btnAddDynamicButton.frame = frame; [btnAddDynamicButton addTarget:self action:@selector(onAddButtonClicked) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btnAddDynamicButton];}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
3. 运行程序.
0 0
- iOS: 学习笔记, 动态添加按钮
- 【代码笔记】iOS-UIActionSheet动态添加按钮
- iOS 动态添加按钮
- iOS开发:动态添加按钮
- IOS AlertView动态添加按钮
- iOS开发:动态添加按钮
- iOS学习之动态添加Button和监听UIAlertView按钮
- iOS学习之动态添加Button和监听UIAlertView按钮
- iOS学习之动态添加Button和监听UIAlertView按钮
- iOS学习之动态添加Button和监听UIAlertView按钮
- iOS开发1:动态添加按钮
- iOS虚拟键盘上添加动态按钮
- iOS虚拟键盘上添加动态按钮
- iOS学习基础学习之动态添加Button和监听UIAlertView按钮
- 01-学习iOS的动态添加Button和监听UIAlertView按钮的点击事件()
- iOS学习笔记—— UINavigationController(一)实现页面跳转&添加左右侧按钮
- ckeditor 学习笔记【2】添加自定义按钮
- 在iOS虚拟键盘上添加动态隐藏按钮
- centos5安装yum及phpredisadmin安装
- 项目管理和缺陷跟踪工具 Redmine
- Android 自定义权限 (<permission> <uses-permission>)
- TQ210开发板人脸检测代码优化(2)
- 只有程序员才有的十大烦恼
- iOS: 学习笔记, 动态添加按钮
- I2C总线之(一)---概述
- 微信及朋友圈分享
- Lua面向对象代码(继承和多态)的读后感
- android学习之路-3-run
- 二分逼近&二分查找 高效解析800万大数据之区域分布
- Flat UI – 基于 Twitter Bootstrap 的扁平风格 UI 工具包
- 2014省赛小结
- NYOJ 16 矩形嵌套