简体   繁体   English

设置颜色以编程方式绘制的视图

[英]Setting the Colour a Programmatically Drawn View

I'm in the middle of fixing my UITextView to not show underneath the keyboard, but instead to resize it to the correct constraints.我正在修复我的 UITextView 以不显示在键盘下方,而是将其调整为正确的约束。 This is probably a stupid question and there is most likely an easy fix alongside this stupid question, but I need to colour the view, that is currently black, to a whiteColor - and it seems that I'm blanking on the correct line of code to do so.这可能是一个愚蠢的问题,并且很可能在这个愚蠢的问题旁边有一个简单的解决方法,但我需要将当前为黑色的视图着色为whiteColor - 似乎我在正确的代码行上空白这样做。 I have searched Stack Overflow and Google for sometime but I have not found a single line of code that doesn't return error(s).我在 Stack Overflow 和 Google 上搜索了一段时间,但没有找到一行不返回错误的代码。

The black rectangle behind the keyboard.键盘后面的黑色矩形。截屏

- (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];
    }
}

Assuming self.companyTextField is what you're talking about:假设self.companyTextField是你所说的:

self.companyTextField.backgroundColor = [UIColor whiteColor];

If you're talking about the main view:如果你在谈论主视图:

self.view.backgroundColor = [UIColor whiteColor];

Set the background color of the container view to white.将容器视图的背景颜色设置为白色。 (the main window view) and also the scrollview background color to white. (主窗口视图)以及滚动视图背景颜色为白色。

Or if you have another view behind it set it to white.或者,如果您后面有另一个视图,请将其设置为白色。

Edit: Your code shows a scrollview, check its color.编辑:您的代码显示滚动视图,检查其颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM