background image

9

    //设置背景颜色 

10

    label.backgroundColor = [UIColor blueColor];   

11

    //设置文字颜色   

12

    label.textColor = [UIColor whiteColor];   

13

    //设置显示位置居中   

14

    label.textAlignment = UITextAlignmentCenter;   

15

    //设置字体大小   

16

       label.font  =  [UIFont  fontWithName:[[UIFont  familyNames]  objectAtIndex:10] 

size:20];  

17

    //将 label 添加到显示视图中 

18

    [self.view addSubview:label];  

19

     

20

    //释放对象     

21

    [label release]; 

22

}

运行程序

 如图所示 使用视图添加的文本内容 与使用代码添加的文本内容都出现在了屏幕

当中。

使用可视化布局添加一个按钮

1

#import <UIKit/UIKit.h> 

2
3

@interface HelloWorldViewController : UIViewController 

4

5

    //定义了一个按钮 buttonA   

6

    IBOutlet UIButton *buttonA;   

7

    //定义了一个按钮 buttonB 

8

    UIButton *buttonB; 

9
10

11

//声明 A 按钮被按下的一个方法(IBAction) 相当于(void)   

12

-(IBAction)bttonPressed:(id)obj;     

13
14
15

-(void)showDialog; 

16

@end

在右侧栏中点中

 鼠标 New Referencing Outlet 拉出一条线到左侧箭头指示方块上松开鼠标

 

这是会显示上面定义的

IBOutlet UIButton ,选中这个 buttonA 标示这个拖动的 button 控件

buttonA 绑定在了一起,然后鼠标点击右侧 Touch up inside 同样拉出一条线到左侧箭头

指示方块上松开鼠标

 这时候会显示上面定义的方法 buttonPressed 选中后 则标示 这个按钮

点击后程序执行

buttonPressed 方法。

                   找软件资料,就到一览软件文库

http://wk.yl1001.com/rj/