【问题标题】:Monotouch - DialogViewController's TableView Background Changes Background of Elements As WellMonotouch - DialogViewController 的 TableView 背景也改变了元素的背景
【发布时间】:2012-08-31 23:06:27
【问题描述】:

我有一个带有 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,但没有成功。

任何提示将不胜感激。

【问题讨论】:

    标签: background xamarin.ios tableview viewcontroller dialogviewcontroller


    【解决方案1】:

    也许这行得通:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-18
      相关资源
      最近更新 更多