Guest User

Untitled

a guest
Jan 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. import UIKit
  2.  
  3. class CardView: UIButton {
  4. override func draw(_ rect: CGRect) {
  5. //activating this function enables the borders, even when I draw a Bezier path in this function the borders doesn't disappear
  6. }
  7. }
  8.  
  9. import UIKit
  10.  
  11. class CardContainerView: UIView {
  12.  
  13. // Create Cards
  14. var cardViews = [CardView](){
  15. didSet {
  16. for card in cardViews {
  17. addSubview(card)
  18. card.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
  19. card.layer.borderColor = UIColor.white.cgColor
  20. card.layer.borderWidth = 0
  21. }
  22. }
  23. }
  24.  
  25. private(set) var grid = Grid(layout: Grid.Layout.aspectRatio(3/2))
  26.  
  27. /// The centered rect in which the buttons are going to be positioned.
  28. private var centeredRect: CGRect {
  29. get {
  30. return CGRect(x: bounds.size.width * 0.025,
  31. y: bounds.size.height * 0.025,
  32. width: bounds.size.width * 0.95,
  33. height: bounds.size.height * 0.95)
  34. }
  35. }
  36.  
  37. override func layoutSubviews() {
  38. super.layoutSubviews()
  39.  
  40. grid.cellCount = cardViews.count
  41. grid.frame = centeredRect
  42.  
  43. for i in 0...cardViews.count {
  44. if let frame = grid[i] {
  45. cardViews[i].frame = frame
  46. cardViews[i].layer.cornerRadius = 10
  47. cardViews[i].layer.borderColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0)
  48. cardViews[i].layer.borderWidth = 0.0
  49. }
  50. }
  51. }
  52. }
Add Comment
Please, Sign In to add comment