代码之家  ›  专栏  ›  技术社区  ›  Ali Ihsan URAL

更改UIView图层-Swift

  •  -1
  • Ali Ihsan URAL  · 技术社区  · 6 年前

    enter image description here

    但我想像下面的图片一样排列

    enter image description here

    元素从右边排序!

    imageView.trailingAnchor.constraint(equalTo: participantView.safeAreaLayoutGuide.trailingAnchor, constant: CGFloat(-(counter * widthX - 5 * counter)) ).isActive = true
    

    我现在能做什么?

       let widthX = 30
       var counter = 0
       for x in element {
    
              guard let image = x.image else { continue }
              let urlX = URL(string: "...")
              let imageView = UIImageView()
              participantView.addSubview(imageView)
    
              imageView.translatesAutoresizingMaskIntoConstraints = false
              imageView.trailingAnchor.constraint(equalTo: participantView.safeAreaLayoutGuide.trailingAnchor, constant: CGFloat(-(counter * widthX - 5 * counter)) ).isActive = true
              imageView.topAnchor.constraint(equalTo: participantView.topAnchor, constant: 0).isActive = true
              imageView.bottomAnchor.constraint(equalTo: participantView.bottomAnchor, constant: 0).isActive = true
              imageView.widthAnchor.constraint(equalToConstant: 30).isActive = true
              imageView.backgroundColor = .white
    
              imageView.layer.cornerRadius = 15
              imageView.clipsToBounds = true
              imageView.contentMode = .scaleAspectFit
              imageView.layer.borderWidth = 1
              imageView.layer.borderColor = UIColor.lightGray.cgColor
              counter += 1
    
              imageView.kf.setImage(with: urlX)
       }
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   Shehata Gamal    6 年前

    替换

    participantView.addSubview(imageView)
    

    具有

    participantView.insertSubview(imageView,at:0)
    

    1,2..等的位置(左/右对齐)取决于图像