| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- //
- // AKExcelCollectionViewCell.swift
- // YunYingSwift
- //
- // Created by AlasKu on 17/2/10.
- // Copyright © 2017年 innostic. All rights reserved.
- //
- import UIKit
- class AKExcelCollectionViewCell: UICollectionViewCell {
-
- var horizontalMargin : CGFloat? {
- didSet{
- setupFrame()
- }
- }
- var customView : UIView? {
- didSet{
- guard let customView = customView else { return }
- customView.frame = bounds
- contentView.insertSubview(customView, at: 0)
- textLabel.text = ""
- }
- }
-
- lazy var textLabel : UILabel = {
-
- let label = UILabel()
- label.numberOfLines = 0
- label.textAlignment = .center
- label.backgroundColor = UIColor.clear
- return label
- }()
-
- private lazy var separatorLayer : CAShapeLayer = {
-
- let lay = CAShapeLayer.init()
- lay.strokeColor = UIColorFromHex(rgbValue: 0x000, alpha: 0.8).cgColor
- lay.lineWidth = 0.5
- return lay
- }()
-
- override init(frame: CGRect) {
- super.init(frame: frame)
- setup()
- }
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- func setup() {
- addSubview(textLabel)
- contentView.layer.addSublayer(separatorLayer)
- }
-
- override func layoutSubviews() {
- super.layoutSubviews()
- setupFrame()
- }
-
- func setupFrame() {
-
- let newFrame = CGRect(x: horizontalMargin!, y: 0, width: bounds.width - 2 * horizontalMargin!, height: bounds.height)
-
- textLabel.frame = newFrame
-
- let path = UIBezierPath()
- path.move(to: CGPoint(x: bounds.width - 0.5, y: 0))
- path.addLine(to: CGPoint(x: bounds.width - 0.5, y: bounds.height))
- path.move(to: CGPoint(x: 0, y: bounds.height - 0.5))
- path.addLine(to: CGPoint(x: bounds.width, y: bounds.height - 0.5))
- separatorLayer.path = path.cgPath
- }
-
- override func prepareForReuse() {
- super.prepareForReuse()
- customView?.removeFromSuperview()
- }
- }
|