如何在背景图像中设置图像(表示如何在背景图像中粘贴图像)。我在UIViewController中将一个图像作为背景图像。现在我想把另一个图像放在背景图像中。我知道如何将图像作为背景图像放在UIViewController中。但我不知道如何将图像放在背景图像中。我尝试了代码。但是图像将会没有在背景图片中显示。这是我的代码。请帮助我任何身体。谢谢。
-(void)viewDidLoad
{
backgroundImage=[UIImage imageNamed:@"bg-small.PNG"];
audioViewBackgroundImage=[[UIImageView alloc]initWithImage:backgroundImage];
[self.view addSubview:audioViewBackgroundImage];
mImage=[UIImage imageNamed:@"muluguphoto.png"];
mBackgroundImage=[[UIImageView alloc]initWithFrame:CGRectMake(20, 160, 150, 90)];
mBackgroundImage=[[UIImageView alloc]initWithImage:mImage];
[audioViewBackgroundImage addSubview:mBackgroundImage];
}
答案 0 :(得分:2)
将其添加到viewDidLoad ..
UIImageView *newImage=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[newImage setBackgroundColor:[UIColor redColor]];//here else you can add image
[self.view addSubview:newImage];
UITableView *newTable=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[newTable setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:newTable];
答案 1 :(得分:1)
将此行添加到viewDidLoad
self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
答案 2 :(得分:1)
你必须在userinterface.like中将imageview设置在photo.make的heirARCHY!并根据需要设置图像视图INDependentaly。这是带有徽标图像的背景图像..
答案 3 :(得分:0)
为什么要两次初始化mBackgroundImage?
让我们尝试以下代码,让我知道结果。
UIImageView * audioViewBackgroundImage=[[UIImageView alloc] initWithFrame:self.view.frame];
audioViewBackgroundImage.image = [UIImage imageNamed:@"bg-small.PNG"];
[self.view addSubview:audioViewBackgroundImage];
UIImageView * mBackgroundImage =[[UIImageView alloc]initWithFrame:CGRectMake(20, 160, 150, 90)];
mBackgroundImage.image = [UIImage imageNamed:@"muluguphoto.png"];
[audioViewBackgroundImage addSubview:mBackgroundImage];
谢谢!
答案 4 :(得分:0)
UIImageView * bgImage = [[UIImageView alloc] initWithFrame:self.view.frame];
bgImage.image = [UIImage imageNamed:@“myimg.png”]; [self.view addSubview:bgImage];
[self.view sendSubviewToBack:bgImage];
答案 5 :(得分:0)
//在viewdidload中写下这一行,并确保通过复制它来导入项目中的图像。
当您编写此行代码时,此图像将自动替换以前的背景图像
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@" stack.jpeg"]];