【问题标题】:highlight the 'return' button on the iOS keyboard突出显示 iOS 键盘上的“返回”按钮
【发布时间】:2012-02-11 11:21:28
【问题描述】:

我正在尝试找到一种方法来突出显示标准 ios 键盘上的返回按钮,但我没有找到任何文档。

有人知道怎么做吗?

非常感谢您的回答。

【问题讨论】:

  • 下次发帖前,请记住根据常见问题解答不允许签名,请检查您的帖子是否存在拼写和语法错误。
  • 好的,谢谢,我不知道...
  • 苹果官方文档显示“Go”按钮高亮显示 (developer.apple.com/library/IOs/#documentation/StringsTextFonts/…)。这是怎么做到的?
  • 好像没人知道啊????
  • 我为你开始了赏金活动,希望能引起一些关注。

标签: ios keyboard return highlight


【解决方案1】:

返回按钮无法高亮,UIReturnKeyType的不同值存在高亮状态:

typedef enum {
    UIReturnKeyDefault,
    UIReturnKeyGo,
    UIReturnKeyGoogle,
    UIReturnKeyJoin,
    UIReturnKeyNext,
    UIReturnKeyRoute,
    UIReturnKeySearch,
    UIReturnKeySend,
    UIReturnKeyYahoo,
    UIReturnKeyDone,
    UIReturnKeyEmergencyCall,
} UIReturnKeyType;

除了UIReturnKeyDefault(顺便说一句“返回”)之外,所有这些都出现了蓝色突出显示。

您可以在任何符合UITextInputTraits 的文本输入控件上设置UIReturnKeyType(例如UITextFieldUITextView[id <UITextInputTraits> returnKeyType]

【讨论】:

    【解决方案2】:

    如果你想再自定义一下你的 textView,我找到了一个关于 how to add a custom button to the keyboard 的例子。该代码的日期为 2008 年 3 月,我无法使其在 iOS5 上运行,但您可以理解:

    @synthesize window;
    @synthesize viewController;
    
    - (void)applicationDidFinishLaunching:(UIApplication *)application {    
    
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
        window.backgroundColor = [UIColor blackColor];
        [window addSubview:viewController.view];
        [window makeKeyAndVisible];
    }
    
    - (void)keyboardWillShow:(NSNotification *)note {
    
        //The UIWindow that contains the keyboard view
        UIWindow* tempWindow;
    
        //Because we cant get access to the UIKeyboard throught the SDK we will just use UIView. 
        //UIKeyboard is a subclass of UIView anyways
        UIView* keyboard;
    
        //Check each window in our application
        for(int c = 0; c < [[[UIApplication sharedApplication] windows] count]; c ++)
        {
            //Get a reference of the current window
            tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:c];
    
            //Get a reference of the current view 
            for(int i = 0; i < [tempWindow.subviews count]; i++)
            {
                keyboard = [tempWindow.subviews objectAtIndex:i];
    
                if([[keyboard description] hasPrefix:@"(lessThen)UIKeyboard"] == YES)
                {
                    //Keyboard is now a UIView reference to the UIKeyboard we want. From here we can add a subview
                    //to th keyboard like a new button
                    dot = [UIButton buttonWithType:UIButtonTypeCustom];
                    dot.frame = CGRectMake(0, 163, 106, 53);
                    [dot setImage:[UIImage imageNamed:@"period.gif"] forState:UIControlStateNormal];
                    [dot setImage:[UIImage imageNamed:@"period2.gif"] forState:UIControlStateHighlighted];
                    [keyboard addSubview:dot];
                    [dot addTarget:self action:@selector(addDot:)  forControlEvents:UIControlEventTouchUpInside];
    
                    return;
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      • 1970-01-01
      • 2015-09-01
      • 1970-01-01
      • 2010-10-09
      相关资源
      最近更新 更多