gpt4 book ai didi

ios - 如何在 Swift 中使用色调和一些文本向 UIImageView 添加叠加层?

转载 作者:行者123 更新时间:2023-11-28 12:44:48 32 4
gpt4 key购买 nike

我创建了一个 UIStackView,其中包含用于启动图库的 UIImageView。但是,此 UIStackView 将仅显示 3 个项目,第三个项目将覆盖图库中的图像数量。类似于下图:

enter image description here

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

最佳答案

  1. 像主视图一样创建 UIView“dynamicView”
  2. 创建一个 UIImageView 添加到“dyanamicView”
  3. 为 transparentColor shadow.named as "tranpView"创建另一个 View
  4. 创建标签并将位置居中。标签添加到“tranpView”
  5. 最后将“dynamicView” View 添加到 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"

    Output

关于ios - 如何在 Swift 中使用色调和一些文本向 UIImageView 添加叠加层?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38389856/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com