Reputation: 1067
All, I need to create a grid of UIViews, in another square UIView (which is bigger). So I want to create UIViews of x=20,y=20 which will make a grid in a UIView.
I know how to create a UIVew programatically in swift, for example :
let rectangle = UIView(frame: CGRectMake(location.x, location.y, 20, 20))
rectangle.backgroundColor = UIColor.redColor()
self.view.addSubview(rectangle)
but whats the best way to add this UIView to another UIView and NOT the main one.
So I have the main UIView which covers the screen and a smaller one which is for the grid and then I want UIViews to make the grid ?
Any help would be brilliant, and better than me making over a hundred UIIViews in IB.
Upvotes: 1
Views: 778
Reputation: 41246
Use a UICollectionView.
Far and away the best solution for creating a grid layout.
Upvotes: 3