Search code examples
swiftviewuicollectionviewreusabilitycode-reuse

Swift reusable Views


at the moment I'm working on a gamecollection app, where the user has to entry his name name and then can select one of 4 games. My plan is it, to have on every gameview a part at the top, with players 1 and players 2 Name, Score, Winrate etc. I want to build it once and then reuse this view (or how ever it is called properly) on all 4 gameviews. I dont want to build the same view 4 times. Later on i just wanna fill the labels according to the game. So on Game1 Players1 Winrate for Game1 should appear, and on Game2 Players1 Winrate for Game2 and so on. I tried to use a container view, but i was unable to do some outlets of the labels on the view.

Hopefully someone can explain me my mistakes i did or show me a way i can do it properly.

Best regards, XaNNy0


Solution

  • Why did you want to use collectionView? Make simple UIView subclass with labels. Add this view to the top of your global view and update labels when you want.