我正在修復我的UITextView而不在鍵盤下方顯示,而是將其調整爲正確的約束。這可能是一個愚蠢的問題,並且這個愚蠢的問題最有可能是一個簡單的解決方法,但是我需要將視圖顏色變爲whiteColor
- 而且我似乎在正確的代碼行上空白這樣做。我搜索了Stack Overflow和Google一段時間,但是我還沒有找到一行不返回錯誤的代碼。以編程方式將顏色設置爲繪製視圖
鍵盤後面的黑色矩形。
- (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];
}
}
將容器視圖的背景顏色設置爲白色。 (主窗口視圖)以及滾動視圖背景色爲白色。或者,如果您有其他視圖,請將其設置爲白色。通過查看圖像看起來你實際上調整了視圖的大小,而不是textview。 – Pochi
通常self.view顏色是黑色的,並且您使用的是scrollview。因爲我們不清楚哪個視圖是黑色的。將self.view的顏色設置爲紅色並將scrollview設置爲藍色。並檢查,以便我們可以很容易地知道哪個視圖具有黑色背景色,以便我們可以輕鬆修復 –
@CharanGiri設置'self.view'的背景顏色似乎做了預期的事情,但我不明白我將如何設置'scrollview'的背景顏色。 [SelfViewRedScreenshot.png](http://i.imgur.com/wHnuLmH.png?1) –