1. 创建UI控件

< ![CDATA[

ios开发首先离开不了Ui的标示

首先介绍2种方式创建

1.xib文件的创建

  -->. 新建项目--Empty--输入名字确定

  --> 默认是没选择xib文件和其他选项的.就是一个空项目,

  -->然后新建一个xib文件,到项目里面

 --> 在AppDelegate.m 的didFinishLaunchingWithOptions 方法种加入

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    
  下面的是加入的代码 
 
   NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:nil ];
  [self.window addSubview:[views lastObject]];
  
return YES; }

 把新建的view.xib addSubview后.

--> 打开xib.从右边拖放一个label到上面去,双击设置显示文字,设置背景色 等

 

第二种方式是代码创建..这种方式在开发种更常见

  -->. 新建项目--Empty--输入名字确定(还是默认不选择xib文件等选项)

--> 在AppDelegate.m 的didFinishLaunchingWithOptions 方法种加入

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
   
  //下面是加入的方法
  UILabel  *label = [[UILabel alloc]initWithFrame:CGRectMake(320/2-140/2, 80,140 , 40)];
  
  label.text = @"hello word22";
  
  label.backgroundColor=[UIColor cyanColor];
  label.textAlignment = NSTextAlignmentCenter;
  [self.window addSubview:label];
  [label release];
    
    return YES;
}

 然后运行 :

 

2种方式创建.

]]>

你可能感兴趣的:(UI)