88
99import UIKit
1010
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+ */
1116public class BaseView : UIView , BackgroundViewable , MarginAdjustable {
1217
1318 /*
1419 MARK: - IB outlets
1520 */
1621
22+ /**
23+ Fulfills the `BackgroundViewable` protocol and is the target for
24+ the optional `tapHandler` block. Defaults to `self`.
25+ */
1726 @IBOutlet public var backgroundView : UIView ! {
1827 didSet {
1928 if let old = oldValue {
@@ -23,6 +32,17 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
2332 }
2433 }
2534
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+ */
2646 @IBOutlet public var contentView : UIView !
2747
2848 /*
@@ -47,6 +67,15 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
4767 MARK: - Installing content
4868 */
4969
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+ */
5079 public func installContentView( contentView: UIView , insets: UIEdgeInsets = UIEdgeInsetsZero) {
5180 contentView. autoresizingMask = [ . FlexibleWidth, . FlexibleHeight]
5281 contentView. translatesAutoresizingMaskIntoConstraints = true
@@ -59,6 +88,9 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
5988 MARK: - Tap handler
6089 */
6190
91+ /**
92+ An optional tap handler that will be called when the `backgroundView` is tapped.
93+ */
6294 public var tapHandler : ( ( view: BaseView ) -> Void ) ? {
6395 didSet {
6496 installTapRecognizer ( )
@@ -87,6 +119,10 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
87119
88120 /*
89121 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).
90126 */
91127
92128 @IBInspectable public var bounceAnimationOffset : CGFloat = 5.0
@@ -98,6 +134,12 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
98134 MARK: - Setting preferred height
99135 */
100136
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+ */
101143 public var preferredHeight : CGFloat ? {
102144 didSet {
103145 setNeedsLayout ( )
@@ -118,6 +160,7 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
118160
119161extension BaseView {
120162
163+ /// A convenience method to configure a default drop shadow effect.
121164 public func configureDropShadow( ) {
122165 let layer = backgroundView. layer
123166 layer. shadowColor = UIColor . blackColor ( ) . CGColor
0 commit comments