UI_02 基础视图、程序启动流程

⼀、UITextField

UITextField(输⼊框):是控制⽂本输⼊和显⽰的控件

UITextField核⼼功能主要包含3个⽅⾯: ⽂本显⽰ 输⼊控制 外观配置

1、⽂本显⽰

//    textField.text = @"你好";

//    textField.textAlignment = NSTextAlignmentCenter;

    textField.textColor = [UIColor blueColor];

    textField.placeholder = @"请输入我爱编程";

    textField.font = [UIFont fontWithName:@"" size:20];


2、输⼊控制

    textField.enabled = YES;
    textField.
clearsOnBeginEditing = NO;
    textField.
secureTextEntry = YES;
    textField.
keyboardType = UIKeyboardTypeDefault;

    textField.returnKeyType = UIReturnKeyDefault;

//自定义键盘视图
   
UIView * inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 180)];
    inputView.
backgroundColor = [UIColor blueColor];
    textField.
inputView = inputView;
    [inputView
release];
//自定义键盘辅助视图
   
UIView * inputAccessaryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 60)];
    inputAccessaryView.
backgroundColor = [UIColor yellowColor];
    textField.
inputAccessoryView = inputAccessaryView;

    [inputAccessaryView release];


3、外观控制

    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.
clearButtonMode = UITextFieldViewModeWhileEditing;

    //设置文本框左视图

    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];

    button.frame = CGRectMake(0, 0, 40, 40);

    [button setBackgroundImage:[UIImage imageNamed:@"face_monkey_2_24px_541648_easyicon.net.png"] forState:UIControlStateNormal];

    textField.leftView = button;

    textField.leftViewMode = UITextFieldViewModeAlways;



二、UIButton

1、UIButton的状态

normal(普通状态)

默认情况

对应的枚举常量:UIControlStateNormal

highlighted(高亮状态)

按钮被按下去的时候(手指还未松开)

对应的枚举常量:UIControlStateHighlighted

disabled(失效状态,不可用状态)

如果enabled属性为NO,就是处于disable状态,代表按钮不可以被点击

对应的枚举常量:UIControlStateDisabled

UIButton有很多种状态,它提供了一些便捷属性,可以直接获取当前状态下的文字、文字颜色、图片等
@property(nonatomic,readonly,retain) NSString *currentTitle;
@property(nonatomic,readonly,retain) UIColor  *currentTitleColor;
@property(nonatomic,readonly,retain) UIImage  *currentImage;

@property(nonatomic,readonly,retain) UIImage  *currentBackgroundImage;



    UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
//    button.backgroundColor = [UIColor blackColor];
    button.
frame = CGRectMake(30, 100, 50, 50);
//    button.layer.cornerRadius = 20;
   
//设置前景图片
    [button
setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
   
//设置背景图片
   
//设置普通状态下的背景图片
    [button
setBackgroundImage:[UIImage imageNamed:@"normal.png"] forState:UIControlStateNormal];
   
//设置高亮状态下的背景图片
    [button
setBackgroundImage:[UIImage imageNamed:@"hilighted.png"] forState:UIControlStateHighlighted];
   
//添加事件
    [button
addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
   
//设置按钮title
    [button
setTitle:@"绿鸟" forState:UIControlStateNormal];
    [button
setTitle:@"蓝鸟" forState:UIControlStateHighlighted];

    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];


- (void)clickButton:(UIButton *)button
{
   
self.window.backgroundColor = [UIColor colorWithRed:random()%100/100.0 green:random()%100/100.0 blue:random()%100/100.0 alpha:1];
    button.
backgroundColor = [UIColor whiteColor];

}



三、AppDelegate

****键盘收回****

1、将AppDelegate作为UITextField的delegate

@interface AppDelegate : UIResponder <UIApplicationDelegate, UITextFieldDelegate>

2、AppDelegate.m⽂件实现textFieldShouldReturn:⽅法

- (void)textFieldDidBeginEditing:(UITextField *)textField

{
    [textField
becomeFirstResponder];
   
NSLog(@"%s", __FUNCTION__);

}// became first responder

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{

    NSLog(@"%s", __FUNCTION__);     // 输出方法名

    [textField resignFirstResponder];
   
return YES;

}// called when 'return' key pressed. return NO to ignore.

3、添加代理

    textField.delegate = self;


****触摸键盘外空白区域隐藏键盘****

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{
   
UITouch *touch = [touches anyObject];
   
   
if (![touch.view isKindOfClass: [UITextField class]] || ![touch.view isKindOfClass: [UITextView class]]) {
       

        [self.window endEditing:YES];       

    }

    [super touchesBegan:touches withEvent:event];

}



四、iOS程序启动流程

1、程序入口

int main(int argc, char * argv[]) {

    @autoreleasepool {

        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }

}


UIApplicationMain剖析:

    argc: argv[].count

    argv[]: 存放的是所有的参数

    principalClassName:如果是nil,UIApplicationMain()函数会给系统创建一个UIApplication这个类的一个对象,而且是唯一的,叫做应用程序对象

    delegateClassName:UIApplicationMain()使用给定类创建代理并给应用程序设置代理

    UIApplicationMain()这个函数,开启事件循环

2、UIApplicationDelegate

UIApplicationDelegate是⼀个OC的协议。⾥⾯声明了⼀堆⽅法,这些⽅ 法都与应⽤程序运⾏状态有关,它们由应⽤程序代理实现。UIApplication 对象负责调⽤。

iOS生命周期:

UIApplicationDelegate

程序启动:

application:didFinishLaunchingWithOptions:

applicationDidBecomeActive:

挂起:

applicationWillResignActive:     (tag:按两下Home键只发送此消息)

applicationDidEnterBackground:

恢复:

applicationWillEnterForeground:

applicationDidBecomeActive:     (tag:从此状态返回程序只发送此消息)

结束:

applicationWillResignActive:   

applicationDidEnterBackground:

AppDelegate applicationWillTerminate:

输出函数名:

    NSLog(@"%s", __FUNCTION__);


转载于:https://my.oschina.net/zooyf/blog/493650

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值