forked from HabitRPG/habitica-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChallengeDetailHeaderView.swift
48 lines (41 loc) · 1.48 KB
/
ChallengeDetailHeaderView.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
//
// ChallengeDetailHeaderView.swift
// Habitica
//
// Created by Phillip Thelen on 01/03/2017.
// Copyright © 2017 HabitRPG Inc. All rights reserved.
//
import UIKit
import Down
import Habitica_Models
class ChallengeDetailHeaderView: UIView {
@IBOutlet weak private var nameLabel: UILabel!
@IBOutlet weak private var notesLabel: UITextView!
@IBOutlet weak private var memberCountLabel: UILabel!
@IBOutlet weak private var gemCountLabel: UILabel!
var showMoreAction: (() -> Void)?
@IBAction func showMoreTapped(_ sender: Any) {
if let action = self.showMoreAction {
action()
}
}
func set(challenge: ChallengeProtocol) {
notesLabel.textContainer.maximumNumberOfLines = 5
notesLabel.textContainer.lineBreakMode = .byTruncatingTail
nameLabel.text = challenge.name?.unicodeEmoji
if let notes = challenge.notes {
notesLabel.attributedText = try? Down(markdownString: notes.unicodeEmoji).toHabiticaAttributedString()
}
memberCountLabel.text = String(challenge.memberCount)
gemCountLabel.text = String(challenge.prize)
}
override var intrinsicContentSize: CGSize {
let size = super.intrinsicContentSize
var height = size.height
let width = size.width
height += nameLabel.intrinsicContentSize.height + 8
height += notesLabel.intrinsicContentSize.height + 8
height += 38
return CGSize(width: width, height: height)
}
}