简体   繁体   English

在iphone中设置视图的背景图像

[英]setting view's background image in iphone

Can I set an image for the view's own background image? 我可以为视图自己的背景图像设置图像吗? I don't want to use UIImageView control. 我不想使用UIImageView控件。 It seems not to be possible using IB. 似乎不可能使用IB。 Do I have to do it programatically? 我是否必须以编程方式执行此操作?

Thank you. 谢谢。

多么浪费资源,使用:

[[self view] setBackgroundColor: [UIColor colorWithPatternImage: [UIImage imageNamed:@"background.png"]]];
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"plain_bg.png"]];

I really don't think that using backgroundColor in this way is the proper way to do things. 我真的不认为以这种方式使用backgroundColor是正确的做事方式。 Personally, I would create a UIImageView and insert it into your view hierarchy. 就个人而言,我会创建一个UIImageView并将其插入到您的视图层次结构中。

UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"pic.png"]];
self.view.backgroundColor = background;

Try this Its working for me 试试这个适合我

What's wrong with UIImageView? UIImageView出了什么问题? This is a perfect use for it. 这是一个完美的用途。

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

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