1

我有一个带有 2 个主要子视图的 UIViewController。一个子视图是 UIViewController,另一个是 DialogViewController。DialogViewController 包含一些元素。我有一个我想在 DVC 后面分配的自定义背景,因此当用户向上或向下滚动时,会显示背景,直到他们松开手指或鼠标并且视图弹回其原始位置。

问题是,当我使用通过搜索找到的方法分配背景时,元素看起来很清晰,并在视图加载时通过它们显示背景。但是,当我滚动到足以在弹回之前将元素推离屏幕时,元素的背景就会变回白色。我希望我的元素始终是白色的,并且只有背景作为我的自定义图像。

我用来尝试实现此目的的代码如下:

// Declare my background
UIImage background = UIImage.FromBundle("images/background.png");

// Assign background pattern to dvc's ParentViewController -- which is my NavigationController (Not sure if this is what it should be)

dvc.TableView.BackgroundColor = UIColor.Clear;
dvc.ParentViewController.View.BackgroundColor = UIColor.FromPatternImage(background);

我也尝试过分配给 dvc.TableView.BackgroundView ,但没有成功。

任何提示将不胜感激。

4

1 回答 1

0

也许这有效:

UIView background = new UIView(dvc.TableView.Bounds);
background.BackgroundColor = UIColor.Green;

dvc.TableView.BackgroundView = background;

如果 dvc 中有许多其他“根”,则必须继承 UINavigationControllerDelegate 并覆盖“WillShowViewController”。只需将代码放入此方法中即可。

于 2012-11-14T08:25:41.090 回答