在UIViewController(MonoTouch)中设置背景图像
我有一个名为HomeScreen的实现UIViewController的屏幕。我希望为这个屏幕使用背景图片。是否有可以覆盖的事件来在HomeScreen.cs文件中设置此背景图像?在UIViewController(MonoTouch)中设置背景图像
尝试设置你的视图的BACKGROUNDCOLOR
myview.BackgroundColor = UIColor.FromPatternImage(UIImage.FromFile("myimage.png"));
有没有什么办法可以让图像缩放到视图的大小,并仍然使用它作为背景颜色? – nhenrique
@nhenrique我也想知道这个,你有没有找到解决方案? –
@nhenrique我已经为你的问题添加了一个[新答案](https://*.com/a/47618726/4332059) –
尝试添加类似下面你MyViewNameViewController.cs:
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.View.BackgroundColor = UIColor.FromPatternImage(UIImage.FromFile("splash.png"));
}
我投了对其他的答案,但是今天IPhone具有不同大小和加载图像的正确方法是使用UIImage.FromBundle
方法:
这里是项目中的断言目录:
要管理的图像:
public override void ViewDidLoad()
{
base.ViewDidLoad();
// replace "name" with the desired name in the asset catalog
this.View.BackgroundColor = UIColor.FromPatternImage(UIImage.FromBundle("name"));
}
UIViewController的犯规相当有BackgroundView /图像会员,你必须创建一个UImageView然后addSubView重复:HTTP:// *.com/questions/2991040/uiviewcontroller-with-background-image – Anuj
谢谢。这不是一个重复,因为我的问题是与MonoTouch相关的。 –
但是,如果您可以在MonoTouch中显示您的建议,我很乐意看到它。听起来这是我最好的选择。谢谢! –