简体   繁体   English

无法在UIView的背景中设置图像?

[英]Unable to set image in background of UIView?

I am trying to put image in background of UIView. 我试图将图像放在UIView的背景中。 Problem is that my view(subView) is inside the main view. 问题是我的视图(子视图)在主视图内。

它很简单:

yourSubView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"BackgroundImage.png"]];

Class: 类:

@interface abc : UIView {
.......
}

In class define subview: 在类中定义子视图:

IBOutlet UIView* subView;

set background image of subView as: 将subView的背景图像设置为:

UIColor* bgrColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed: backgroundImageName]];
subView.backgroundColor = bgrColor;

Finally add subview to the View 最后将子视图添加到视图

[self.view addSubView:subView];

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

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