2013-12-20 105 views
2

我正在修复我的UITextView而不在键盘下方显示,而是将其调整为正确的约束。这可能是一个愚蠢的问题,并且这个愚蠢的问题最有可能是一个简单的解决方法,但是我需要将视图颜色变为whiteColor - 而且我似乎在正确的代码行上空白这样做。我搜索了Stack Overflow和Google一段时间,但是我还没有找到一行不返回错误的代码。以编程方式将颜色设置为绘制视图

键盘后面的黑色矩形。 Screenshot

- (void)keyboardDidShow:(NSNotification *)aNotification { 
    NSDictionary* info = [aNotification userInfo]; 
    CGRect kbRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; 
    kbRect = [[self view] convertRect:kbRect fromView:nil]; 
    CGSize kbSize = kbRect.size; 
    CGRect aRect = self.view.frame; 

    /* This should work, but doesn't quite qet the job done */ 
    // UIEdgeInsets insets = self.textView.contentInset; 
    // insets.bottom = kbSize.height; 
    // self.textView.contentInset = insets; 
    // 
    // insets = self.textView.scrollIndicatorInsets; 
    // insets.bottom = kbSize.height; 
    // self.textView.scrollIndicatorInsets = insets; 

    /* Instead, we just adjust the frame of the uitextview */ 
    aRect.size.height -= kbSize.height + VERTICAL_KEYRBOARD_MARGIN; 
    self.companyTextField.frame = aRect; 

    // If active text field is hidden by keyboard, scroll it so it's visible 
    // Your application might not need or want this behavior. 
    if (!CGRectContainsPoint(aRect, self.companyTextField.frame.origin)) { 
     CGPoint scrollPoint = CGPointMake(0.0, self.companyTextField.frame.origin.y - kbSize.height); 
     [self.companyTextField setContentOffset:scrollPoint animated:YES]; 
    } 
} 
+0

将容器视图的背景颜色设置为白色。 (主窗口视图)以及滚动视图背景色为白色。或者,如果您有其他视图,请将其设置为白色。通过查看图像看起来你实际上调整了视图的大小,而不是textview。 – Pochi

+0

通常self.view颜色是黑色的,并且您使用的是scrollview。因为我们不清楚哪个视图是黑色的。将self.view的颜色设置为红色并将scrollview设置为蓝色。并检查,以便我们可以很容易地知道哪个视图具有黑色背景色,以便我们可以轻松修复 –

+0

@CharanGiri设置'self.view'的背景颜色似乎做了预期的事情,但我不明白我将如何设置'scrollview'的背景颜色。 [SelfViewRedScreenshot.png](http://i.imgur.com/wHnuLmH.png?1) –

回答

1

假设self.companyTextField是你在说什么:

self.companyTextField.backgroundColor = [UIColor whiteColor]; 

如果你在谈论的主要观点:

self.view.backgroundColor = [UIColor whiteColor]; 
+1

由于textview正在调整大小,他在讨论背后的观点。 – Pochi

+0

是的,@Chiquis所指的是我想要着色的东西。不幸的是,您的原创或编辑似乎都不起作用。 :( –

+0

@MattBush我认为这是因为你有一个黑色背景的滚动视图 – Pochi

1

将容器的背景颜色查看到白色。 (主窗口视图)以及滚动视图背景色为白色。

或者如果您有其他视图,请将其设置为白色。

编辑:您的代码显示滚动视图,检查其颜色。

+0

是的,我试着设置背景颜色:'self.view.backgroundColor = [UIColor whiteColor];',我也将每个属性设置为'whiteColor'的属性。 –

+0

我可能错了,你似乎没有滚动视图,而是滚动文本框的内容?奇怪的是,通常你有一个覆盖屏幕的大滚动视图,并且你设置了这个滚动视图的内容偏移量来移动整个文本视图。你的注释代码这么说“//如果活动文本字段被键盘隐藏,请将其滚动以使其可见” – Pochi

相关问题