Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在Swift中使用色调和一些文本向UIImageView添加覆盖?_Ios_Swift_Uiimageview_Uiimage - Fatal编程技术网

Ios 如何在Swift中使用色调和一些文本向UIImageView添加覆盖?

Ios 如何在Swift中使用色调和一些文本向UIImageView添加覆盖?,ios,swift,uiimageview,uiimage,Ios,Swift,Uiimageview,Uiimage,我创建了一个UIStackView,其中包含UIImageViews以启动库。但是,此UIStackView仅显示3个项目,第三个项目将与库中的图像数重叠。与下图类似: 问题是,;如何在Swift中的UIImageView上添加黑色和“+3”文本?您可以使用具有3个子视图的UIView: UIImagegallery是UIImageView UIView黑色背景色,alpha 0.3 ui标签带有+3文本 您可以使用具有3个子视图的ui视图: UIImagegallery是UIImageVie

我创建了一个
UIStackView
,其中包含
UIImageView
s以启动库。但是,此
UIStackView
仅显示3个项目,第三个项目将与库中的图像数重叠。与下图类似:


问题是,;如何在Swift中的
UIImageView
上添加黑色和“+3”文本?

您可以使用具有3个子视图的
UIView

  • UIImage
    gallery是
    UIImageView
  • UIView
    黑色背景色,alpha 0.3
  • ui标签
    带有+3文本
    您可以使用具有3个子视图的
    ui视图

  • UIImage
    gallery是
    UIImageView
  • UIView
    黑色背景色,alpha 0.3
  • ui标签
    带有+3文本
  • 创建UIView“dynamicView”,将其作为主视图
  • 创建UIImageView添加到“动态视图”
  • 为透明彩色阴影创建另一个视图。名为“tranpView”
  • 创建标签并使位置居中。标签已添加到“tranpView”
  • 最后将“dynamicView”视图添加到self.view

       let dynamicView=UIView(frame: CGRectMake(0, 200, 200, 200))
        dynamicView.backgroundColor=UIColor.clearColor()
    
        let imageView=UIImageView(frame: CGRectMake(0, 0, 200, 200))
        imageView.image = UIImage(named: "bg.png")
        dynamicView.addSubview(imageView)
    
        let tranpView=UIView(frame: CGRectMake(0, 0, 200, 200))
        tranpView.backgroundColor = UIColor.whiteColor()
        tranpView.backgroundColor = tranpView.backgroundColor!.colorWithAlphaComponent(0.3)
    
        let label = UILabel(frame: CGRectMake(0, 0, 50, 50))
        label.text = "+3"
        label.font = UIFont.systemFontOfSize(20)
        label.center = tranpView.center;
        tranpView.addSubview(label)
    
         dynamicView.addSubview(tranpView)
    
        self.view.addSubview(dynamicView)
      //Just add to stackView directly replace the "self.view"
    

  • 创建UIView“dynamicView”,将其作为主视图
  • 创建UIImageView添加到“动态视图”
  • 为透明彩色阴影创建另一个视图。名为“tranpView”
  • 创建标签并使位置居中。标签已添加到“tranpView”
  • 最后将“dynamicView”视图添加到self.view

       let dynamicView=UIView(frame: CGRectMake(0, 200, 200, 200))
        dynamicView.backgroundColor=UIColor.clearColor()
    
        let imageView=UIImageView(frame: CGRectMake(0, 0, 200, 200))
        imageView.image = UIImage(named: "bg.png")
        dynamicView.addSubview(imageView)
    
        let tranpView=UIView(frame: CGRectMake(0, 0, 200, 200))
        tranpView.backgroundColor = UIColor.whiteColor()
        tranpView.backgroundColor = tranpView.backgroundColor!.colorWithAlphaComponent(0.3)
    
        let label = UILabel(frame: CGRectMake(0, 0, 50, 50))
        label.text = "+3"
        label.font = UIFont.systemFontOfSize(20)
        label.center = tranpView.center;
        tranpView.addSubview(label)
    
         dynamicView.addSubview(tranpView)
    
        self.view.addSubview(dynamicView)
      //Just add to stackView directly replace the "self.view"
    


  • 哪一个将是另一个的子视图?我尝试将子视图添加到UIImageView,但对我无效。正如我所提到的,使用一个超级视图,它将有3个子视图(图像视图、着色视图和标签)。当我这样做时,它会导致UIStackView出现问题,是否有其他替代解决方案?哪一个将是其他视图的子视图?我尝试将子视图添加到UIImageView,但对我无效。正如我所提到的,使用一个超级视图,它将有3个子视图(图像视图、着色视图和标签)。当我这样做时,它会导致UIStackView出现问题,是否有其他替代解决方案?看起来我对此有问题。你能看一下吗?看起来我有点问题。你能看一下吗?