iOS零零碎碎

来源:互联网 发布:c 编写unity3d脚本 编辑:程序博客网 时间:2024/06/05 19:19

一、数字键盘上添加移除按钮

- (void)handleKeyboardDidShow:(NSNotification *)notification

{

    if (doneInKeyboardButton ==nil)

    {

        doneInKeyboardButton = [[UIButtonbuttonWithType:UIButtonTypeCustom]retain];

        

        CGFloat screenHeight = [[UIScreenmainScreen] bounds].size.height;

        if(screenHeight==568.0f){//爱疯5

            doneInKeyboardButton.frame =CGRectMake(0, 568 -53, 106, 53);

        }else{//3.5

            doneInKeyboardButton.frame =CGRectMake(0, 480 -53, 106, 53);

        }

        

        doneInKeyboardButton.adjustsImageWhenHighlighted =NO;

        //图片直接抠腾讯财付通里面的= =!

        [doneInKeyboardButtonsetImage:[UIImageimageNamed:@"btn_done_up@2x.png"]forState:UIControlStateNormal];

        [doneInKeyboardButtonsetImage:[UIImageimageNamed:@"btn_done_down@2x.png"]forState:UIControlStateHighlighted];

        [doneInKeyboardButtonaddTarget:selfaction:@selector(finishAction)forControlEvents:UIControlEventTouchUpInside];

    }

    

    

    UIWindow* tempWindow = [[[UIApplicationsharedApplication] windows] objectAtIndex:1];

    

    if (doneInKeyboardButton.superview ==nil)

    {

        [tempWindow addSubview:doneInKeyboardButton];   // 注意这里直接加到window

    }

    

}

- (void)handleKeyboardWillHide:(NSNotification *)notification

{

    if (doneInKeyboardButton.superview)

    {

        [doneInKeyboardButtonremoveFromSuperview];

    }

}


关闭键盘:

[[[UIApplicationsharedApplication] keyWindow] endEditing:YES];//关闭键盘  

以上部分摘自code4app.com

原创粉丝点击