【问题标题】:How to set the image in Background image in UIViewController in ios如何在ios中的UIViewController中设置背景图像中的图像
【发布时间】:2014-03-15 05:22:10
【问题描述】:

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

【问题讨论】:

  • 请任何人帮助我....

标签: ios iphone objective-c xcode uiimageview


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    您必须在 userinterface 中的 imageview 上方设置 imageview。就像在 photo.make 正确的 heirARCHY 中一样!并根据需要设置 imageview INDependentaly 的框架。这里是带有徽标图像的背景图像..

    【讨论】:

      【解决方案3】:

      将此行添加到 viewDidLoad

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

      【讨论】:

      • @brother Parvendra Kumar 你明白我的问题了吗?我已经显示“bg-small.PNG”这是我的背景 iamge。现在我想设置另一个图像,如“mluguimage.png”这个图像放在上面的背景图片中。
      • @user3222991 兄弟只是替换你的图像......你想在图像下设置哪个图像......将这些图像设置为视图的背景图像以及要在前面显示的图像(创建一个图像视图并在此设置另一个图像)。这是解决方案
      【解决方案4】:

      为什么要两次初始化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];
      

      谢谢!

      【讨论】:

      • 感谢您的回复。我尝试了您的代码。但它不起作用。我的要求是“bg-small.PNG”这是我的背景图像。除了图像下没有其他内容。和“mluguphoto.png”这是我的正面图片。这是我的要求
      • 请检查图片文件名和app bundle中是否存在?您是否将 imageView 背景颜色设置为清除颜色?这两个图像的大小相同吗?你想在第一张图片上绘制第二张图片吗?如果可能,粘贴您的结果屏幕截图。
      【解决方案5】:

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

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

      [self.view sendSubviewToBack:bgImage];

      【讨论】:

        【解决方案6】:

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

        当你写这行代码时,这张图片会自动替换之前的背景图片

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-07-11
          • 2010-10-06
          • 2018-01-08
          相关资源
          最近更新 更多