IOS 代码创建控件,并有处理事件
2015-01-21 21:10
429 查看
@interface AppDelegate() @property UILabel* show; @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; //创建一个UIViewController 对象 UIViewController* controller = [[UIViewController alloc] init]; //让该程序的窗口加载并显示 viewController 视图控制器关联的用户界面 self.window.rootViewController = controller; //创建一个UIView 对象 UIView* rootView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; //设置 controller 显示 rootView 控件 controller.view = rootView; //创建一个圆角按钮 UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //设置按钮的大小 button.frame = CGRectMake(120, 100, 80, 40); //为按钮设置文本 [button setTitle:@"确定" forState:UIControlStateNormal]; //将按钮添加到 rootView 控件中 [rootView addSubview:button]; //创建一个 UILabel 对象 self.show = [[UILabel alloc] initWithFrame:CGRectMake(60, 40, 180, 30)]; // UILabel* show = [[UILabel alloc] initWithFrame:CGRectMake(60, 40, 180, 30)]; //将UILabel 添加到 rootView 控件中 [rootView addSubview: self.show]; //设置 UILabel 默认显示的文本 self.show.text = @"初始文本"; self.show.backgroundColor = [UIColor grayColor]; //为圆角按钮的触碰事件绑定事件处理方法 [button addTarget:self action:@selector(clickHandler:) forControlEvents:UIControlEventTouchUpInside]; //将该 UIWindow 对象设为主窗口并显示出来 [self.window makeKeyAndVisible]; return YES; }
- (void)clickHandler:(id)sender { self.show.text = @"开始学习 IOS 吧!"; }
相关文章推荐
- IOS动态创建控件通过tag处理单击事件
- iOS代码实现:创建按钮,绑定按钮事件,读取控件值
- C#控件事件处理代码的复用
- iOS拦截控件事件,处理后继续执行原来的消息传递流程
- 黑马程序员——IOS学习—基本UI控件的代码创建
- 5.ios之代码创建控件和排版
- C#中动态创建控件及事件处理程序、置于顶层
- C#中动态创建控件及事件处理程序
- 【iOS基础控件 - 2 】 用代码创建控件,不用storyboard
- Android 动态创建Android控件、绑定事件处理的新方法
- (委托事件处理)关于多线程执行显示进度条的实例(转)&&线程间操作无效: 从不是创建控件“rtxtEntryNO”的线程访问它。
- C#中动态创建控件及事件处理程序
- iOS开发学习笔记 -- (二)动态添加控件和事件处理
- VB 用代码创建的控件和接收事件
- 在C# WinForm程序中创建控件数组及相应的事件处理
- C#中动态创建控件及事件处理程序
- C#中动态创建控件及事件处理程序
- 动态创建控件及控件的事件处理
- 代码创建UIWindow -> UIView -> RootViewController中遇到UIview覆盖,控件事件不响应问题
- 【iOS开发-88】事件传递原理解释哪个控件处理事件以及响应者链条的介绍