8
8
9
9
import UIKit
10
10
11
+ /*
12
+ The `BaseView` class is a reusable message view base class that implements some
13
+ of the optional SwiftMessages protocols and provides some convenience methods
14
+ and a configurable tap handler. Message views do not need to inherit from `BaseVew`.
15
+ */
11
16
public class BaseView : UIView , BackgroundViewable , MarginAdjustable {
12
17
13
18
/*
14
19
MARK: - IB outlets
15
20
*/
16
21
22
+ /**
23
+ Fulfills the `BackgroundViewable` protocol and is the target for
24
+ the optional `tapHandler` block. Defaults to `self`.
25
+ */
17
26
@IBOutlet public var backgroundView : UIView ! {
18
27
didSet {
19
28
if let old = oldValue {
@@ -23,6 +32,17 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
23
32
}
24
33
}
25
34
35
+ /**
36
+ The view containing the message view content and the target of the
37
+ `installContentView` convenience method. Defaults to `self`.
38
+
39
+ This view has no specific functionality in SwiftMessages, but is provided
40
+ as a reference to the content as a convenience. It is a distinctly separate
41
+ property from `backgroundView`, though they may point to the same view (and
42
+ they both point to `self` by default) to accommodate `UIStackViews` as
43
+ content views, which do not render a background
44
+ (see MessageView.nib and CardView.nib).
45
+ */
26
46
@IBOutlet public var contentView : UIView !
27
47
28
48
/*
@@ -47,6 +67,15 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
47
67
MARK: - Installing content
48
68
*/
49
69
70
+ /**
71
+ A convenience method for installing a content view as a subview of `backgroundView`
72
+ and pinning the edges to `backgroundView` with the specified `insets`.
73
+
74
+ - Parameter contentView: The view to be installed into the background view
75
+ and assigned to the `contentView` property.
76
+ - Parameter insets: The amount to inset the content view from the background view.
77
+ Default is zero inset.
78
+ */
50
79
public func installContentView( contentView: UIView , insets: UIEdgeInsets = UIEdgeInsetsZero) {
51
80
contentView. autoresizingMask = [ . FlexibleWidth, . FlexibleHeight]
52
81
contentView. translatesAutoresizingMaskIntoConstraints = true
@@ -59,6 +88,9 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
59
88
MARK: - Tap handler
60
89
*/
61
90
91
+ /**
92
+ An optional tap handler that will be called when the `backgroundView` is tapped.
93
+ */
62
94
public var tapHandler : ( ( view: BaseView ) -> Void ) ? {
63
95
didSet {
64
96
installTapRecognizer ( )
@@ -87,6 +119,10 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
87
119
88
120
/*
89
121
MARK: - MarginAdjustable
122
+
123
+ These properties fulfill the `MarginAdjustable` protocol and are exposed
124
+ as `@IBInspectables` so that they can be adjusted directly in nib files
125
+ (see MessageView.nib).
90
126
*/
91
127
92
128
@IBInspectable public var bounceAnimationOffset : CGFloat = 5.0
@@ -98,6 +134,12 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
98
134
MARK: - Setting preferred height
99
135
*/
100
136
137
+ /**
138
+ An optional value that sets the message view's intrinsic content height.
139
+ This can be used as a way to specify a fixed height for the message view.
140
+ Note that this height is not guaranteed depending on anyt Auto Layout
141
+ constraints used within the message view.
142
+ */
101
143
public var preferredHeight : CGFloat ? {
102
144
didSet {
103
145
setNeedsLayout ( )
@@ -118,6 +160,7 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
118
160
119
161
extension BaseView {
120
162
163
+ /// A convenience method to configure a default drop shadow effect.
121
164
public func configureDropShadow( ) {
122
165
let layer = backgroundView. layer
123
166
layer. shadowColor = UIColor . blackColor ( ) . CGColor
0 commit comments