如何在iPhone上扩展键盘渐变?
我发现很less有应用程序正在扩展键盘,但我想知道他们是如何做到的。
这里有两个例子。
Textastic & Prompt
现在我知道我可以将inputAccessoryView添加到UITextView,但它仍然有一个细小的线条从UIToolbar分离键盘像下面的图像。
他们怎么做? 扩展UIWindow持有键盘或以其他方式?
更新1与答案:
所以我用Tyraz写的解决scheme。
- 子类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;
这就是应用于其中的解决scheme的样子
我会尝试使用inputAccessoryView加上第二个视图位于分隔线顶部和“填补空白”。
一旦inputAccessoryView添加到键盘(覆盖配件UIView子类中的didMoveToSuperview方法以在发生这种情况时得到通知),将其添加到inputAccessoryView的超级视图。
在你的附件UIView子类中应该是这样的:
- (void)didMoveToSuperview { [self.separatorHideView removeFromSuperview]; CGRect seperatorRect = CGRectMake(self.frame.origin.x, self.frame.origin.y + self.frame.size.height, self.frame.size.width, 2.0); UIImage *gapGradient = [UIImage imageNamed:@"GapGradient"]; self.separatorHideView = [[UIImageView alloc]initWithImage:gapGradient]; self.separatorHideView.frame = seperatorRect; [self.superview addSubview:self.separatorHideView]; }
我也会覆盖你的附件UIView子类中的setFrame来更新gapView的框架,以防万一键盘的框架被改变。
在iOS 7上,您可以创build一个inputAccessoryView
来轻松地匹配键盘样式:
[[UIInputView alloc] initWithFrame:<#frame#> inputViewStyle:UIInputViewStyleKeyboard];