added iOS source code
[wl-app.git] / iOS / WolneLektury / Screens / Common / Views / BookImageOverlayView.swift
1 //
2 //  BookImageOverlayView.swift
3 //  WolneLektury
4 //
5 //  Created by Pawel Dabrowski on 18/06/2018.
6 //  Copyright © 2018 Fundacja Nowoczesna Polska. All rights reserved.
7 //
8
9 import UIKit
10
11 class BookImageOverlayView: DesignableXibView {
12     
13         @IBOutlet weak var iconsView: UIView!
14         @IBOutlet weak var readImageView: UIImageView!
15         @IBOutlet weak var audiobookImageView: UIImageView!
16         @IBOutlet weak var iconsWidthConstraint: NSLayoutConstraint!
17         @IBOutlet weak var titleLabel: UILabel!
18         @IBOutlet weak var textBgColorView: UIView!
19
20
21         override func awakeFromNib() {
22             super.awakeFromNib()
23             readImageView.layer.cornerRadius = 9
24             audiobookImageView.layer.cornerRadius = 9
25             readImageView.tintColor = UIColor.white
26             audiobookImageView.tintColor = UIColor.white
27             
28             let color = UIColor(red:0.84, green:0.29, blue:0.19, alpha:0.9)
29             readImageView.backgroundColor = color
30             audiobookImageView.backgroundColor = color
31             textBgColorView.alpha = 0.9
32
33         }
34         
35         func setup(bookModel: BookModel){
36             let titleAttributedText = bookModel.getAttributedAuthorAndTitle(titleFont: UIFont.systemFont(ofSize: 9, weight: .medium), descFont: UIFont.systemFont(ofSize: 11, weight: .bold))
37             
38             readImageView.backgroundColor = bookModel.bgColor
39             audiobookImageView.backgroundColor = bookModel.bgColor
40             textBgColorView.backgroundColor = bookModel.bgColor
41             titleLabel.attributedText = titleAttributedText
42
43             if bookModel.has_audio{
44                 audiobookImageView.isHidden = false
45                 iconsWidthConstraint.constant = 39
46             }
47             else{
48                 audiobookImageView.isHidden = true
49                 iconsWidthConstraint.constant = 18
50             }
51         }
52 }
53