Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Item into Views #22

Open
indrac opened this issue Apr 3, 2017 · 3 comments
Open

Add Item into Views #22

indrac opened this issue Apr 3, 2017 · 3 comments

Comments

@indrac
Copy link

indrac commented Apr 3, 2017

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)
              }
}
@terenceLuffy
Copy link
Owner

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

@indrac
Copy link
Author

indrac commented Apr 12, 2017

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

@terenceLuffy
Copy link
Owner

terenceLuffy commented Apr 12, 2017

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants