我发现很少有应用程序可以扩展键盘,但我想知道它们是如何做到的。
这里有 2 个例子。
文字学 http://www.textasticapp.com/images/screenshot_iphone5.png &
Prompt https://pbs.twimg.com/media/A6SCZlXCAAETFJu.png:large
现在我知道我可以将 inputAccessoryView 添加到 UITextView,但它仍然有一条细线将键盘与 UIToolbar 分开,如下图所示。
他们是如何做到的?扩展容纳键盘的 UIWindow 或以其他方式?
更新 1 的答案:
所以我使用了 Tyraz 编写的解决方案。
- 子类 UIToolbar
- 我使用 UIView 代替图像,背景颜色与键盘渐变的完成颜色相同,并使用 UIViewAutoResizingMaskFlexibleWidth,以便在旋转时覆盖键盘,高度为 3 像素
这是子类 UIToolbar 的代码
- (void)didMoveToSuperview {
[self.separatorHideView removeFromSuperview];
CGRect seperatorRect = CGRectMake(self.frame.origin.x,
self.frame.size.height,
self.frame.size.width,
3.0);
self.separatorHideView = [[UIView alloc]];
self.separatorHideView.backgroundColor = [UIColor colorWithRed:0.569 green:0.600 blue:0.643 alpha:1.000];
self.separatorHideView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self addSubview:self.separatorHideView];
}
更新 2:这是我如何将其添加到 UITextView 以及我使用什么颜色进行色调的代码。
我使用以下代码将其添加到 viewDidLoad 中的 UITextView
CustomToolbar *accessoryToolbar = [[CustomToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 38)];
accessoryToolbar.tintColor = [UIColor colorWithRed:0.569 green:0.600 blue:0.643 alpha:1.000];
editor.inputAccessoryView = accessoryToolbar;
这就是应用解决方案后的样子