2013-12-20 109 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

相關問題