UIButton,UIView,UITextField

今天是第一次没完成作业,这尼玛比lol还难。

在头文件中还要继承协议《UITextFieldDelegate》

#import "AppDelegate.h"

@interface AppDelegate ()
{
    UIWindow *_window ;
}

@end

@implementation AppDelegate


- (void)dealloc
{
    [_window release];
    [super dealloc];
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    _window.backgroundColor = [UIColor whiteColor];

#pragma mark--------------UITextField
    //0.开辟空间初始化

    UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(20, 50, 200, 44)];

    //1.与文本相关的属性设置
//    textField.text = @"13016792211";

//    textField.textColor = [UIColor whiteColor];
//    textField.hidden = YES;
    textField.borderStyle = UITextBorderStyleRoundedRect;

//    textField.textColor = [UIColor redColor];

    textField.textAlignment = NSTextAlignmentCenter;



    //提示占位符
    textField.placeholder = @"请输入电话号码";



    //与输入控制相关的属性
    //是否允许输入,默认为yes;
//    textField.enabled = NO;

    //输入时是否清空文本框

    textField.clearsOnBeginEditing = YES;


    //以密码的形式展示
    textField.secureTextEntry = YES;




    //自定义键盘视图
    textField.keyboardType = UIKeyboardTypeNumberPad;

    textField.keyboardType = UIKeyboardTypeURL;

    textField.returnKeyType = UIReturnKeyJoin;


    //自定义键盘视图
    //宽度无效
//    UIView  *inputview= [[UIView alloc]initWithFrame:CGRectMake(0,1000, 0, 190)];
//    inputview.backgroundColor = [UIColor purpleColor];
//    textField.inputView = inputview;


    //自定义键盘辅助视图

    UIView *inputAccess = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 30)];
    inputAccess.backgroundColor = [UIColor yellowColor];


    textField.inputAccessoryView = inputAccess;

//    [inputview release];
    [inputAccess release];

    //外观的相关设置
    textField.borderStyle = UITextBorderStyleRoundedRect ;


    //设置清除按钮的显示
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;

    UIButton  *leftView = [UIButton buttonWithType:UIButtonTypeCustom];
    leftView.frame = CGRectMake(0, 0, 40, 40);
    [leftView setBackgroundImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];



    textField.leftViewMode  = UITextFieldViewModeAlways;
    textField.leftView = leftView;

    //添加到父视图上面


    [_window addSubview:textField];
    [_window makeKeyAndVisible];



#warning -----------设置UITextFoeld的代理

    textField.delegate = self;


    return YES;
}
//开始编辑
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    NSLog(@"%s",__FUNCTION__);
    return YES;
}// return NO to disallow editing.
//已经编辑
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    [textField becomeFirstResponder];
     NSLog(@"%s",__FUNCTION__);
}// became first responder

//结束编辑
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    NSLog(@"%s",__FUNCTION__);
    return YES;
}// return YES to allow editing to stop and to resign first responder status. NO to disallow the editing session to end
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    NSLog(@"%s",__FUNCTION__);
}// may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSLog(@"%s",__FUNCTION__);
    return YES;
}// return NO to not change text


//text被清空时
- (BOOL)textFieldShouldClear:(UITextField *)textField
{
    NSLog(@"%s",__FUNCTION__);
    return YES;
}// called when clear button pressed. return NO to ignore (no notifications)



//点击return键时
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    //取消第一响应者
    [textField resignFirstResponder];

    NSLog(@"%s",__FUNCTION__);
    return YES;
}// called when 'return' key pressed. return NO to ignore.
@interface AppDelegate ()
{
    UIWindow *_window;
    UIButton *_button;
}

@end

@implementation AppDelegate

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{



    _window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    _window.backgroundColor = [UIColor whiteColor];

    _button = [UIButton buttonWithType:UIButtonTypeCustom ];

    _button.frame = CGRectMake(40, 40, 100, 100);

    _button.backgroundColor = [UIColor greenColor];


    //给按钮添加点击事件
    [_button addTarget:self action:@selector(changered) forControlEvents:UIControlEventTouchUpInside];

    [_window addSubview:_button];


    /*
    说明:由于是在“iOS 模拟器”中测试的,所以不能用手指,只能用鼠标。

    1)UIControlEventTouchDown

    指鼠标左键按下(注:只是“按下”)的动作

    2)UIControlEventTouchDownRepeat

    3)UIControlEventTouchDragInside

    指按下鼠标,然后在控件边界范围内拖动。

    4)UIControlEventTouchDragOutside

    与 UIControlEventTouchDragInside不同的是,拖动时,鼠标位于控件边界范围之外。但首先得有个 UIControlEventTouchDown事件,然后接一个UIControlEventTouchDragInside事件,再接一个 UIControlEventTouchDragExit事件,这时,鼠标已经位于控件外了,继续拖动就是 UIControlEventTouchDragOutside事件了。

    具体操作是:在控件里面按下鼠标,然后拖动到控件之外。

    5)UIControlEventTouchDragEnter

    指拖动动作中,从控件边界外到内时产生的事件。

    6)UIControlEventTouchDragExit

    指拖动动作中,从控件边界内到外时产生的事件。

    7)UIControlEventTouchUpInside

    指鼠标在控件范围内抬起,前提先得按下,即UIControlEventTouchDown或UIControlEventTouchDownRepeat事件。

    8)UIControlEventTouchUpOutside

    指 鼠标在控件边界范围外抬起,前提先得按下,然后拖动到控件外,即 UIControlEventTouchDown -> UIControlEventTouchDragInside(n 个) -> UIControlEventTouchDragExit -> UIControlEventTouchDragOutside(n 个) 时间序列,再然后就是抬起鼠标,产生UIControlEventTouchUpOutside事件9)UIControlEventTouchCancel

    所有触摸取消事件,即一次触摸因为放上了太多手指而被取消,或者被上锁或者电话呼叫打断。

    10)UIControlEventTouchChanged
    当控件的值发生改变时,发送通知。用于滑块、分段控件、以及其他取值的控件。你可以配置滑块控件何时发送通知,在滑块被放下时发送,或者在被拖动时发送。


    */





    [_window makeKeyAndVisible];



    return YES;
}


-(void)changered{
    _button.backgroundColor = [UIColor redColor];

    UIColor *color = _button.backgroundColor;
}
//
//  AppDelegate.m
//  8_17_UIButton_pm
//
//  Created by lanou3g on 15/8/17.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()
{

    UIButton *_button;
    UIWindow *_window;
    BOOL b;
}

@end

@implementation AppDelegate

- (void)dealloc
{
    [_window dealloc];
    [super dealloc];
}


//应用程序加载完成时
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        NSLog(@"%s",__FUNCTION__);
    _window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    _window.backgroundColor = [UIColor whiteColor];
    _button = [UIButton buttonWithType:UIButtonTypeCustom ];

    _button.frame = CGRectMake(40, 40, 100, 100);

    _button.backgroundColor = [UIColor blueColor];


    //给button设置背景图片
    [_button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

    //设置按钮的标题
    [_button setTitle:@"奥巴马" forState:UIControlStateNormal];

    [_button setTitle:@"熊猫" forState:UIControlStateHighlighted];

    //改变button上字的颜色










    [_window addSubview:_button];

    [_window makeKeyAndVisible];



    return YES;
}


-(void)click:(UIButton *)btn{

    if (!b) {
         _window.backgroundColor = [UIColor greenColor];

        b= 1;
    }else{
        _window.backgroundColor = [UIColor orangeColor];
        b = 0;
    }


    [_button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    //设置普通状态下得背景图片

    [btn setBackgroundImage:[UIImage imageNamed:@"resizeApi.php.png"] forState:UIControlStateNormal];


    //设置高亮状态下得背景图片
    [btn setBackgroundImage:[UIImage imageNamed:@"556429.gif"] forState:UIControlStateHighlighted];
}


//注册
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.


    NSLog(@"%s",__FUNCTION__);
}


//进入后台
- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
        NSLog(@"%s",__FUNCTION__);
}


//从后台进入前台
- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
        NSLog(@"%s",__FUNCTION__);
}


//取消
- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
        NSLog(@"%s",__FUNCTION__);
}


//
- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
        NSLog(@"%s",__FUNCTION__);
}

@end
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值