国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

IOSApplication新建Empty項目中自定義UIButton

2019-11-14 20:06:28
字體:
供稿:網(wǎng)友

最近剛開始學(xué)IOS,用的Xcode5中默認(rèn)生成的Storyboard中控件的好多屬性設(shè)置不了,所以就嘗試在空項目里手寫button,如有錯誤,請指正,共同學(xué)習(xí)。

 

 

 1.新建ViewController類,我起的名字是MCViewController。

 

2.創(chuàng)建mccontroller控制器,并設(shè)置window的根視圖為mccontroller。

 

AppDelegate.m

 1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 2 { 3     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 4     // Override point for customization after application launch. 5     self.window.backgroundColor = [UIColor whiteColor]; 6     [self.window makeKeyAndVisible]; 7     //自定義code 8     MCViewController *mccontroller =[[MCViewController alloc] init]; 9     self.window.rootViewController=mccontroller;10     //code end11     return YES;12 }

 

3.創(chuàng)建按鈕

 

MCViewController.m

 1 - (void)viewDidLoad 2 { 3     [super viewDidLoad]; 4     // Do any additional setup after loading the view. 5      6     //btn_enter 定義 7     UIButton *btn_enter=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 8     btn_enter.frame=CGRectMake(20, 360, 280, 40); 9     btn_enter.backgroundColor = [UIColor clearColor];10     [btn_enter.layer setMasksToBounds:YES];11     [btn_enter.layer setCornerRadius:10.0]; //設(shè)置矩形四個圓角半徑12     [btn_enter.layer setBorderWidth:1.0]; //邊框?qū)挾?/span>13     [btn_enter setTitle:@"點擊" forState:UIControlStateNormal];14     [btn_enter addTarget:self action:@selector(click_btn_enter:) forControlEvents:UIControlEventTouchUpInside];15     [self.view addSubview:btn_enter];16     17     //btn_quit 定義18     UIButton *btn_quit=[UIButton buttonWithType:UIButtonTypeRoundedRect];19     btn_quit.frame=CGRectMake(20, 420, 280, 40);20     btn_quit.backgroundColor=[UIColor clearColor];21     [btn_quit.layer setMasksToBounds:YES];22     [btn_quit.layer setCornerRadius:10];23     [btn_quit.layer setBorderWidth:1.0];24     [btn_quit setTitle:@"退出" forState:UIControlStateNormal];25     [btn_quit addTarget:self action:@selector(click_btn_quit:) forControlEvents:(UIControlEventTouchUpInside)];26     [self.view addSubview:btn_quit];27 }

 

4.聲明按鈕動作

 

MCViewController.h

1 @interface MCViewController : UIViewController2 -(IBAction)click_btn_enter:(UIButton *)sender;3 -(IBAction)click_btn_quit:(UIButton *)sender;4 @end

 

5.實現(xiàn)按鈕動作

 

MCViewController.m

1 -(IBAction)click_btn_enter:(UIButton *)sender{2     NSLog(@"I am enter!!!");3 }4 5 -(IBAction)click_btn_quit:(UIButton *)sender{6     NSLog(@"I am quit!!!");7 }

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 健康| 托克逊县| 黔西| 西平县| 白城市| 林芝县| 象山县| 阿巴嘎旗| 新疆| 阳东县| 洞头县| 龙井市| 盐边县| 宁化县| 德钦县| 延寿县| 南涧| 南木林县| 安图县| 饶平县| 吉隆县| 朝阳县| 江北区| 阿克| 鹿泉市| 湖北省| 汉川市| 乌苏市| 南部县| 双柏县| 新平| 星座| 二手房| 井研县| 沭阳县| 土默特左旗| 高邑县| 二连浩特市| 遵化市| 乌兰浩特市| 祥云县|