2013-07-22 IOS-User Interface

来源:互联网 发布:黑龙江电视台网络直播 编辑:程序博客网 时间:2024/05/21 21:49
ios常用控件
熟悉事件处理机制
iOS动画效果
掌握不同ViewController的使用场景,使用方法
iOS的各种设计模式
iOS硬件特性,会硬件编程
网络应用开发,数据持久化,多线程开发
 

UI加法运算
 UITextFiled,常用于显示少量信息的空间
text
textcolor
 


//

//  AppDelegate.h

//  UI_1

//

//  Created by 0101 on 13-7-22.

//  Copyright (c) 2013 PH. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface AppDelegate : UIResponder <UIApplicationDelegate>

{

    UILabel *label1;

    UITextField *tf1;

    UITextField *tf2;

    UIButton *btn;

    UILabel *result;

    UIWindow *_window;

}

@property (retainnonatomicUIWindow *window;


@end


.m文件 


     CGRect r = CGRectMake(00320508);//创建一个矩形

    

    //属性的赋值方式

    //方式一

     self.window = [[[UIWindow alloc]initWithFrame:r]autorelease];

     self.window.backgroundColor = [UIColor redColor];

    

   //方式二

    UIWindow *aWin = [[UIWindow alloc]initWithFrame:r];//iOS不支持多窗口    iPhone4/4s 320*480像素 iPhone5s 320*508像素  一个App的高度44*44像素 aWin retainCount = 1  

    

    self.window = aWin;//aWin retainCount = 2

    aWin.backgroundColor = [UIColor grayColor];

    [aWin release];//aWin retainCount = 1,此时该 retainCount = 1Window,但是window的引用计数没有变化它还是1,此时只是控制权归window,单这并不代表它的引用计数归谁,拥有控制权就一定要释放。

    

    

    

    //Label 标签

    label1 = [[UILabel alloc]initWithFrame:CGRectMake(10904030)];

    label1.backgroundColor = [UIColor whiteColor];

    label1.text = @"";

    label1.textAlignment = NSTextAlignmentLeft;

    [self.window addSubview:label1];

    [label1 release];

     

    

    //TextFiled 文本输入框 tf1

    tf1= [[UITextField alloc]initWithFrame:CGRectMake(10504030)];

    tf1.borderStyle = UITextBorderStyleLine;

    tf1.contentVerticalAlignment = UIControlContentHorizontalAlignmentCenter;

    tf1.keyboardType = UIKeyboardTypeNumberPad;

    [self.window addSubview:tf1];

    [tf1 release];

    

    

    //加号label

    UILabel *plus = [[UILabel alloc]initWithFrame:CGRectMake(60502030)];

    plus.text = @"+";

    plus.backgroundColor = [UIColor clearColor];

    plus.textAlignment = NSTextAlignmentCenter;

    [self.window addSubview:plus];

    [plus release];

    

    //TextFiled 文本输入框 tf2

    tf2 = [[UITextField alloc]initWithFrame:CGRectMake(100504030)];;

    tf2.borderStyle = UITextBorderStyleLine;

    tf2.keyboardType = UIKeyboardTypeNumberPad;

    [self.window addSubview:tf2];

    [tf2 release];

    

    

    //等号

    UILabel *equal = [[UILabel alloc]initWithFrame:CGRectMake(150502030)];

    equal.backgroundColor = [UIColor clearColor];

    equal.text = @"=";

    equal.textAlignment = NSTextAlignmentCenter;

    [self.window addSubview:equal];

    [equal release];

   

    

   

    

    //计算结果

    result = [[UILabel alloc]initWithFrame:CGRectMake(200504030)];

    result.backgroundColor = [UIColor clearColor];

    result.textAlignment = NSTextAlignmentCenter;

    [self.window addSubview:result];

    [result release];

    

    //Button 按钮

    btn = [UIButton buttonWithType:(UIButtonTypeRoundedRect)];

    btn.frame = CGRectMake(1013010030);

    [btn setTitle:@"计算" forState:(UIControlStateNormal)];

    [btn setTitle:@"[计算]" forState:UIControlStateHighlighted];

    btn.tintColor = [UIColor orangeColor];

    

    //给按钮添加事件

    [btn addTarget:self

            action:@selector(btnClick)

  forControlEvents:(UIControlEventTouchUpInside)];

    [self.window addSubview:btn];

    

    //给按钮添加图片

    [btn setBackgroundImage:[UIImage imageNamed:@"abc.png"]

                   forState:UIControlStateNormal];

    

    [self.window makeKeyAndVisible];

    return YES;



-(void)btnClick

{

    int sum = 0;

    sum = [tf1.text intValue] + [tf2.text intValue];

    result.text = [NSString stringWithFormat:@"%d",sum];

    

} 


UI编程步骤
1、将各种控件根据需要(是否要创建成全局变量)声明在.h文件中
2、@synthesize window = _window; 
3、创建window    CGRect r = CGRectMake(00320508);//创建一个矩形
4、将矩形r赋值给window属性  
     
//方式一      self.window = [[[UIWindow alloc]initWithFrame:r]autorelease];

   //方式二     UIWindow *aWin = [[UIWindow alloc]initWithFrame:r]; //aWin retainCount = 1  

    
/*
    iOS
不支持多窗口 
    iPhone4/4s 320*480像素 
    iPhone5 320*508  
    
一个App的高度44*44 

    */
 

    self.window = aWin;//aWin retainCount = 2

    aWin.backgroundColor = [UIColor grayColor];

    [aWin release];//aWin retainCount = 1,此时该 retainCount = 1Window,但是window的引用计数没有变化它还是1,只是控制权归window,但这并不代表它的引用计数归谁,拥有控制权就一定要释放。

5、根据各种需要编写控件
原创粉丝点击