Skip to content

Commit

Permalink
Shadow added to the board (fixed cell size)
Browse files Browse the repository at this point in the history
  • Loading branch information
yassram committed May 12, 2019
1 parent d56503f commit db406b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
7 changes: 3 additions & 4 deletions WordSearch/Controllers/GameVC+CollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ extension GameVC: UICollectionViewDelegate, UICollectionViewDataSource, UICollec

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: lettreCellIdentifier, for: indexPath) as! LetterCollectionViewCell

cell.backgroundColor = .white
cell.backgroundColor = .clear
if logicPositioning.isInRange(index: indexPath.item, start: startSelected, end: endSelected) {
cell.backgroundColor = .orange
}
Expand All @@ -34,8 +33,8 @@ extension GameVC: UICollectionViewDelegate, UICollectionViewDataSource, UICollec
}

func collectionView(_ collectionView: UICollectionView, layout _: UICollectionViewLayout, sizeForItemAt _: IndexPath) -> CGSize {
let w = collectionView.bounds.width / CGFloat(collumnNumber)
let h = collectionView.bounds.height / CGFloat(lineNumber)
let w = floor(collectionView.bounds.width / CGFloat(collumnNumber))
let h = floor(collectionView.bounds.height / CGFloat(lineNumber))
return CGSize(width: w, height: h)
}

Expand Down
13 changes: 10 additions & 3 deletions WordSearch/Controllers/GameVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class GameVC: UIViewController {
let collectionView: UICollectionView = {
let flowLayout = UICollectionViewFlowLayout()
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)
collectionView.clipsToBounds = true
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.isUserInteractionEnabled = false

Expand Down Expand Up @@ -50,10 +51,16 @@ class GameVC: UIViewController {
func setupViews() {
view.addSubview(collectionView)
collectionView.backgroundColor = .white
collectionView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 8).isActive = true
collectionView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -8).isActive = true
collectionView.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 8).isActive = true
collectionView.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor, constant: -8).isActive = true
collectionView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 0).isActive = true
collectionView.heightAnchor.constraint(equalToConstant: 400).isActive = true
collectionView.heightAnchor.constraint(equalTo: collectionView.widthAnchor).isActive = true
collectionView.layoutIfNeeded()
let spacingX = collectionView.bounds.width - floor(collectionView.bounds.width / CGFloat(collumnNumber)) * CGFloat(collumnNumber)
let spacingY = collectionView.bounds.height - floor(collectionView.bounds.height / CGFloat(lineNumber)) * CGFloat(lineNumber)
collectionView.contentInset = UIEdgeInsets(top: spacingY / 2, left: spacingX / 2, bottom: spacingY / 2, right: spacingX / 2)
collectionView.reloadData()
print(spacingX, spacingY)
}

override func touchesBegan(_ touches: Set<UITouch>, with _: UIEvent?) {
Expand Down

0 comments on commit db406b6

Please sign in to comment.