This repository was archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathTabViewCell.swift
52 lines (43 loc) · 1.49 KB
/
TabViewCell.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// TabViewCell.swift
// reddift
//
// Created by sonson on 2015/10/28.
// Copyright © 2015年 sonson. All rights reserved.
//
import UIKit
extension NSLayoutConstraint {
func setMultiplier(multiplier: CGFloat) {
let newConstraint = NSLayoutConstraint(
item: firstItem as Any,
attribute: firstAttribute,
relatedBy: relation,
toItem: secondItem,
attribute: secondAttribute,
multiplier: multiplier,
constant: constant)
newConstraint.priority = priority
newConstraint.shouldBeArchived = self.shouldBeArchived
newConstraint.identifier = self.identifier
newConstraint.isActive = self.isActive
NSLayoutConstraint.deactivate([self])
NSLayoutConstraint.activate([newConstraint])
}
}
class TabViewCell: UICollectionViewCell {
@IBOutlet var screenImageView: UIImageView?
@IBOutlet var numberLabel: UILabel?
@IBOutlet var widthRatio: NSLayoutConstraint?
@IBOutlet var aspectRatio: NSLayoutConstraint?
override func awakeFromNib() {
super.awakeFromNib()
if let size = UIApplication.shared.keyWindow?.rootViewController?.view.frame.size {
let ratio = size.width / (size.height)
widthRatio?.setMultiplier(multiplier: 0.95)
aspectRatio?.setMultiplier(multiplier: ratio)
}
}
override func prepareForReuse() {
super.prepareForReuse()
}
}