偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

iOS開發(fā)動態(tài)添加按鈕

移動開發(fā) iOS
動態(tài)添加按鈕想要的效果是,單擊一個已有的按鈕后自動創(chuàng)建一個新的按鈕,并為新按鈕添加事件,使得單擊時彈出提示框。

新接觸iPad開發(fā),把最近用到的記下來,省得以后忘記又要找。

想要的效果是,單擊一個已有的按鈕后自動創(chuàng)建一個新的按鈕,并為新按鈕添加事件,使得單擊時彈出提示框。

1、運(yùn)行Xcode 4.2,新建一個Single View Application工程,取名DynamicButton:

2、打開ViewController.xib,拖一個按鈕到視圖,按鈕名設(shè)置為“添加一個按鈕”。

3、選中這個按鈕,按住Ctrl,把按鈕拖到ViewController.h文件指定位置:

松開鼠標(biāo),在彈出的窗口鍵入以下信息:

即為這個按鈕添加響應(yīng)事件 addButton

4、打開ViewController.m,找到addButton函數(shù),添加以下代碼:

  1. - (IBAction)addButton:(id)sender { 
  2.     //動態(tài)添加一個按鈕 
  3.     CGRect frame = CGRectMake(300, 300, 300, 50);  
  4.     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
  5.     button.frame = frame; 
  6.     [button setTitle:@"新添加的動態(tài)按鈕" forState: UIControlStateNormal];   
  7.     button.backgroundColor = [UIColor clearColor];   
  8.     button.tag = 2000; 
  9.     [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];   
  10.     [self.view addSubview:button];   

5、在addButton函數(shù)后邊添加一個函數(shù):

  1. //這個是新按鈕的響應(yīng)函數(shù) 
  2. -(IBAction) buttonClicked:(id)sender {   
  3.     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"  
  4.                                                     message:@"單擊了動態(tài)按鈕!"    
  5.                                                    delegate:self    
  6.                                           cancelButtonTitle:@"確定"   
  7.                                           otherButtonTitles:nil];   
  8.     [alert show]; 
  9.     [alert release]; 

6、編譯并運(yùn)行:

[[70083]]

責(zé)任編輯:閆佳明 來源: oschina
相關(guān)推薦

2011-03-11 14:07:51

Ubuntu 11.0

2020-05-15 10:22:33

WebFlutter動態(tài)化

2013-07-29 05:01:31

iOS開發(fā)iOS開發(fā)學(xué)習(xí)按鈕拖動和點擊

2015-07-23 15:15:06

動態(tài)彈出

2010-01-19 10:12:39

VB.NET Butt

2011-07-29 14:55:25

iPhone開發(fā) 動畫過渡

2011-08-19 15:09:00

IOS開發(fā)

2009-08-11 13:27:09

C#動態(tài)圖像按鈕

2011-12-25 21:00:30

iPhone

2009-01-04 09:57:24

2015-07-09 15:04:53

JSPatch動態(tài)更新ios app

2009-12-17 09:56:26

Linux添加驅(qū)動模塊

2011-08-01 16:50:28

Xcode 動態(tài) View

2010-05-13 10:19:09

Widget開發(fā)

2011-04-08 13:58:10

Android界面設(shè)計

2012-03-31 09:45:08

微軟Windows開始按鈕

2023-05-26 00:14:38

PythonJinJa2

2021-06-25 05:53:09

物聯(lián)網(wǎng)人工智能機(jī)器人

2022-06-27 14:12:32

css鴻蒙自定義

2010-04-14 12:51:04

Oracle動態(tài)
點贊
收藏

51CTO技術(shù)棧公眾號