AppStoreStyleHorizontalScrollView icon indicating copy to clipboard operation
AppStoreStyleHorizontalScrollView copied to clipboard

Add Item into Views

Open indrac opened this issue 7 years ago • 3 comments

I try to customize my views inside horizontalScrollView, but the item only appear on once, not completely iterate. Look like this :

screen shot 2017-04-03 at 4 20 30 pm

I used this code :

if indexPath.row == 0 {
     horizontalScrollView.uniformItemSize = CGSize(width: 80, height: 60)
     horizontalScrollView.setItemsMarginOnce()
                for _ in 1...20{
                    let imageView = UIImageView(frame: CGRect.zero)
                    imageView.image = UIImage(named: "cetakidcard")
                    imageView.contentMode = .scaleAspectFill
                    let viewSome = UIView()
                    viewSome.backgroundColor = UIColor.black
                    
                    let produkLabel = UILabel()
                    produkLabel.text = "Software Antrian"
                    
                    let produkImage = UIImageView()
                    produkImage.image = UIImage(named: "cetakidcard")
                    produkImage.contentMode = .scaleAspectFill
                    
                    produkImage.snp.makeConstraints { make in
                        make.height.equalTo(50)
                        make.width.equalTo(50)
                    }
                    
                    viewSome.addSubview(produkImage)
                    horizontalScrollView.addItem(viewSome)
              }
}

indrac avatar Apr 03 '17 09:04 indrac

I guess this issue relates to the constraints you add to your product image view. What does makeConstraints exactly do except adding height and width constraints? I suggest you can check the frame of each item after viewDidAppear

terenceLuffy avatar Apr 03 '17 13:04 terenceLuffy

Have you tried the horizontalScrollView.addItem() to your custom views?? Because it didn't work.

indrac avatar Apr 12 '17 00:04 indrac

@indrac it works well for me, the screenshots in Readme is from my personal app. I guess you didn't add enough constraints for your image view, as I can see, you only add width and height constraint, you will also need the position constraints for it.

And you also add constraints before adding it to super view, which is wrong. You should add your produkImage to viewSome first and then add constraints with translatesAutoresizingMaskIntoConstraints off for your produkImage

terenceLuffy avatar Apr 12 '17 14:04 terenceLuffy