xcode 如何在ios中的UIViewController中设置背景图像中的图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22419922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:46:12  来源:igfitidea点击:

How to set the image in Background image in UIViewController in ios

iosiphoneobjective-cxcodeuiimageview

提问by user3222991

How to set the image in Background image(means how to paste the image in Background image). I took one image as a background image in UIViewController. Right now i want to put the another image in background image.i know how to put the image as a Background image in UIViewController.But i have no idea how to put the image in background image.I tried the code.But the image will not displayed in background image.This is my code.please help me any body.Thanks in advance.

如何在背景图像中设置图像(表示如何将图像粘贴到背景图像中)。我在 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];
}

回答by Ashish Kakkad

add it to your viewDidLoad..

将它添加到您的 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];

回答by Rushi trivedi

you have to set imageview above imageview in userinterface.like in photo.make proper heirARCHY!and set frame of imageview INDependentaly as you want.here is background image with logo image..enter image description here

你必须在用户界面中的图像视图上方设置图像视图。就像在照片中一样。制作适当的继承人!并根据需要设置图像视图独立的框架。这里是带有徽标图像的背景图像..在此处输入图片说明

enter image description here

在此处输入图片说明

回答by Parvendra Singh

Add this line to viewDidLoad

将此行添加到 viewDidLoad

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

回答by Natarajan

Why do you initializing mBackgroundImage two times?

为什么要初始化 mBackgroundImage 两次?

Let's try the below code and let me know the result.

让我们试试下面的代码,让我知道结果。

    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];

Thanks!

谢谢!

回答by Kumar KL

UIImageView * bgImage =[[UIImageView alloc]initWithFrame:self.view.frame];

UIImageView * bgImage =[[UIImageView alloc]initWithFrame:self.view.frame];

bgImage.image = [UIImage imageNamed:@"myimg.png"]; [self.view addSubview:bgImage];

bgImage.image = [UIImage imageNamed:@"myimg.png"]; [self.view addSubview:bgImage];

[self.view sendSubviewToBack:bgImage];

[self.view sendSubviewToBack:bgImage];

回答by NIKETA SETH

//write this line in viewdidload and make sure that you have import the image in your project by copying it .

//在viewdidload中写入这一行,并确保通过复制将图像导入到项目中。

when you write this line of code then this image will automatically replace the previous background image

当您编写这行代码时,此图像将自动替换之前的背景图像

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"stack.jpeg"]];

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"stack.jpeg"]];