-
Notifications
You must be signed in to change notification settings - Fork 895
/
Copy pathImageBarView.swift
48 lines (35 loc) · 1.15 KB
/
ImageBarView.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
//
// ImageBarView.swift
// TGUIKit
//
// Created by keepcoder on 30/12/2016.
// Copyright © 2016 Telegram. All rights reserved.
//
import Cocoa
public class ImageBarView: BarView {
public var button:ImageButton = ImageButton()
public func set(image:CGImage, highlightImage:CGImage? = nil) {
button.set(image: image, for: .Normal)
if let highlight = highlightImage {
button.set(image: highlight, for: .Highlight)
}
_ = button.sizeToFit()
setFrameSize(NSMakeSize(max(60, image.backingSize.width), frame.height))
}
public override func layout() {
super.layout()
button.center()
}
public init(controller: ViewController, _ image:CGImage, _ highlight:CGImage? = nil) {
super.init(controller: controller)
addSubview(button)
set(image: image, highlightImage: highlight)
}
required public init(frame frameRect: NSRect) {
super.init(frame: frameRect)
addSubview(button)
}
required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}