Skip to content

Commit 538283e

Browse files
committed
Fix BaseView.installContentView()
1 parent 33c0f1e commit 538283e

12 files changed

+105
-88
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## [1.0.3](https://github.com/SwiftKickMobile/SwiftMessages/releases/tag/1.0.2)
5+
6+
### Improvements
7+
8+
* Remove the `iconContainer` property from `MessageView`.
9+
10+
### Bug Fixes
11+
12+
* Fix constraints generated by `BaseView.installContentView()`.
13+
414
## [1.0.2](https://github.com/SwiftKickMobile/SwiftMessages/releases/tag/1.0.2)
515

616
### Feature

Demo/Demo/ExploreViewController.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class ExploreViewController: UITableViewController, UITextFieldDelegate {
6363
}
6464

6565
if !showIcon.on {
66-
view.iconContainer?.hidden = true
66+
view.iconImageView?.hidden = true
67+
view.iconLabel?.hidden = true
6768
}
6869

6970
if !showTitle.on {

Demo/Demo/ViewController.swift

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class ViewController: UITableViewController {
5959
error.configureTheme(.Error)
6060
error.configureContent(title: "Error", body: "Something is horribly wrong!")
6161
error.button?.setTitle("Stop", forState: .Normal)
62-
error.iconContainer?.hidden = true
6362

6463
let warning = MessageView.viewFromNib(layout: .CardView)
6564
warning.configureTheme(.Warning)

Demo/Pods/Pods.xcodeproj/xcuserdata/wtmoose.xcuserdatad/xcschemes/Pods-Demo.xcscheme

+24-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/Pods/Pods.xcodeproj/xcuserdata/wtmoose.xcuserdatad/xcschemes/xcschememanagement.plist

+17-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,22 @@ SwiftMessages.show(config: config, view: view)
108108

109109
### Customization
110110

111-
`MessageView` provides the following UI elements:
111+
`MessageView` provides the following UI elements, exposed as public, optional `@IBOutlets`:
112112

113113
* __Title__ (`UILabel`)
114114
* __Message body__ (`UILabel`)
115-
* __Icon__ (both `UIImageView` and `UILabel` variants)
115+
* __Image Icon__ (`UIImageView`)
116+
* __Text Icon__ (`UILabel`)
116117
* __Button__ (`UIButton`)
117118

118-
All of these are defined as optional `@IBOutlets`, so you can freely omit the ones you don't need. The easiest way to customize `MessageView` is to drag-and-drop one of the provide nib files into your project and make changes. When using one of the `UIStackView`-based layouts as a starting point, you can simply delete elements from the nib file or hide them — no need to adjust the Auto Layout constraints.
119+
Because they are optional, you can freely omit the ones you don't need.
119120

120-
`MessageView` provides some convenience methods for creating the included layouts while `SwiftMessages` provides additional, more generic nib loading methods:
121+
**The easiest way to customize `MessageView` is to drag-and-drop one of the pre-defined nib files into your project and make changes.** SwiftMessages always searches the main bundle for nib files first, so it is not necessary to rename the file or make a different API call. However, there are some OS-specific considerations to be aware of:
122+
123+
* **iOS 9+** When using one of the `UIStackView` layouts, MessageView.nib or CardView.nib, as a starting point, you can simply delete elements from the nib file or hide them — no need to adjust the Auto Layout constraints.
124+
* **iOS 8** When using MessageViewIOS8.nib, you'll delete the unwanted elements and fix up the Auto Layout constraints. Or just create your own nib from scratch, which is much like creating a custom `UITableViewCell` or `UICollectionViewCell` — set the base view's class to `MessageView` or whatever subclass or view class you're using and wire up the outlets.
125+
126+
To facilitate the use of nib-based layouts, `MessageView` provides some type-safe convenience methods for loading the pre-defined nibs. In addition, the `SwiftMessages` class provides some generic loading methods:
121127

122128
````swift
123129
// Instantiate MessageView from one of the provided nibs in a type-safe way.

SwiftMessages.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'SwiftMessages'
3-
spec.version = '1.0.2'
3+
spec.version = '1.0.3'
44
spec.license = { :type => 'MIT' }
55
spec.homepage = 'https://github.com/SwiftKickMobile/SwiftMessages'
66
spec.authors = { 'Timothy Moose' => 'tim@swiftkick.it' }
77
spec.summary = 'A very flexible message bar for iOS written in Swift.'
8-
spec.source = {:git => 'https://github.com/SwiftKickMobile/SwiftMessages.git', :tag => '1.0.2'}
8+
spec.source = {:git => 'https://github.com/SwiftKickMobile/SwiftMessages.git', :tag => '1.0.3'}
99
spec.platform = :ios, '8.0'
1010
spec.ios.deployment_target = '8.0'
1111
spec.source_files = 'SwiftMessages/**/*.swift'

SwiftMessages/BaseView.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,13 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
7777
Default is zero inset.
7878
*/
7979
public func installContentView(contentView: UIView, insets: UIEdgeInsets = UIEdgeInsetsZero) {
80-
contentView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
81-
contentView.translatesAutoresizingMaskIntoConstraints = true
82-
contentView.frame = UIEdgeInsetsInsetRect(self.bounds, insets)
80+
contentView.translatesAutoresizingMaskIntoConstraints = false
8381
backgroundView.addSubview(contentView)
82+
let top = NSLayoutConstraint(item: contentView, attribute: .Top, relatedBy: .Equal, toItem: backgroundView, attribute: .TopMargin, multiplier: 1.0, constant: insets.top)
83+
let left = NSLayoutConstraint(item: contentView, attribute: .Left, relatedBy: .Equal, toItem: backgroundView, attribute: .LeftMargin, multiplier: 1.0, constant: insets.left)
84+
let bottom = NSLayoutConstraint(item: contentView, attribute: .Bottom, relatedBy: .Equal, toItem: backgroundView, attribute: .BottomMargin, multiplier: 1.0, constant: -insets.bottom)
85+
let right = NSLayoutConstraint(item: contentView, attribute: .Right, relatedBy: .Equal, toItem: backgroundView, attribute: .RightMargin, multiplier: 1.0, constant: -insets.right)
86+
backgroundView.addConstraints([top, left, bottom, right])
8487
self.contentView = contentView
8588
}
8689

SwiftMessages/MessageView.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public class MessageView: BaseView, Identifiable {
4545

4646
@IBOutlet public var titleLabel: UILabel?
4747
@IBOutlet public var bodyLabel: UILabel?
48-
@IBOutlet public var iconContainer: UIView?
4948
@IBOutlet public var iconImageView: UIImageView?
5049
@IBOutlet public var iconLabel: UILabel?
5150

@@ -110,6 +109,8 @@ extension MessageView {
110109
button?.tintColor = backgroundColor
111110
button?.contentEdgeInsets = UIEdgeInsetsMake(7.0, 7.0, 7.0, 7.0)
112111
button?.layer.cornerRadius = 5.0
112+
iconImageView?.hidden = iconImageView?.image == nil
113+
iconLabel?.hidden = iconLabel?.text == nil
113114
}
114115
}
115116

@@ -131,13 +132,17 @@ extension MessageView {
131132
public func configureContent(title title: String, body: String, iconImage: UIImage) {
132133
configureContent(title: title, body: body)
133134
iconImageView?.image = iconImage
135+
iconImageView?.hidden = false
134136
iconLabel?.text = nil
137+
iconLabel?.hidden = true
135138
}
136139

137140
public func configureContent(title title: String, body: String, iconText: String) {
138141
configureContent(title: title, body: body)
139-
iconImageView?.image = nil
140142
iconLabel?.text = iconText
143+
iconLabel?.hidden = false
144+
iconImageView?.hidden = true
145+
iconImageView?.image = nil
141146
}
142147

143148
public func configureContent(title title: String?, body: String?, iconImage: UIImage?, iconText: String?, buttonImage: UIImage?, buttonTitle: String?, buttonTapHandler: ((button: UIButton) -> Void)?) {

SwiftMessages/Resources/CardView.xib

+10-27
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,17 @@
1818
<stackView opaque="NO" contentMode="scaleToFill" alignment="center" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="RJH-Fp-YDa" userLabel="Content view">
1919
<rect key="frame" x="20" y="20" width="532" height="93"/>
2020
<subviews>
21-
<view contentMode="scaleToFill" horizontalHuggingPriority="252" horizontalCompressionResistancePriority="752" translatesAutoresizingMaskIntoConstraints="NO" id="cFe-Hg-5FF" userLabel="Icon container">
22-
<rect key="frame" x="0.0" y="22" width="50" height="50"/>
23-
<subviews>
24-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="252" verticalHuggingPriority="251" horizontalCompressionResistancePriority="752" text="😬" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pFx-Py-lZQ" userLabel="Icon label">
25-
<rect key="frame" x="0.0" y="0.0" width="38" height="45.5"/>
26-
<fontDescription key="fontDescription" type="system" pointSize="38"/>
27-
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
28-
<nil key="highlightedColor"/>
29-
</label>
30-
<imageView userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="252" verticalHuggingPriority="251" horizontalCompressionResistancePriority="752" image="errorIcon" translatesAutoresizingMaskIntoConstraints="NO" id="eGt-Nj-7Fu" userLabel="Icon image view">
31-
<rect key="frame" x="0.0" y="0.0" width="38" height="45.5"/>
32-
</imageView>
33-
</subviews>
34-
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
35-
<constraints>
36-
<constraint firstItem="eGt-Nj-7Fu" firstAttribute="top" secondItem="cFe-Hg-5FF" secondAttribute="top" id="4oY-HE-Qmy"/>
37-
<constraint firstAttribute="trailing" secondItem="pFx-Py-lZQ" secondAttribute="trailing" id="Kqe-Zy-nft"/>
38-
<constraint firstItem="pFx-Py-lZQ" firstAttribute="top" secondItem="cFe-Hg-5FF" secondAttribute="top" id="Mxd-2w-2eb"/>
39-
<constraint firstAttribute="bottom" secondItem="eGt-Nj-7Fu" secondAttribute="bottom" id="XKp-Rn-McQ"/>
40-
<constraint firstAttribute="bottom" secondItem="pFx-Py-lZQ" secondAttribute="bottom" id="cdl-57-WWl"/>
41-
<constraint firstItem="pFx-Py-lZQ" firstAttribute="leading" secondItem="cFe-Hg-5FF" secondAttribute="leading" id="kXo-k0-3Nw"/>
42-
<constraint firstAttribute="trailing" secondItem="eGt-Nj-7Fu" secondAttribute="trailing" id="rgg-3H-nhZ"/>
43-
<constraint firstItem="eGt-Nj-7Fu" firstAttribute="leading" secondItem="cFe-Hg-5FF" secondAttribute="leading" id="vfR-tQ-fEp"/>
44-
</constraints>
45-
</view>
21+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="252" verticalHuggingPriority="251" horizontalCompressionResistancePriority="752" text="😬" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pFx-Py-lZQ" userLabel="Icon label">
22+
<rect key="frame" x="0.0" y="24" width="38" height="46"/>
23+
<fontDescription key="fontDescription" type="system" pointSize="38"/>
24+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
25+
<nil key="highlightedColor"/>
26+
</label>
27+
<imageView userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="252" verticalHuggingPriority="251" horizontalCompressionResistancePriority="752" image="errorIcon" translatesAutoresizingMaskIntoConstraints="NO" id="eGt-Nj-7Fu" userLabel="Icon image view">
28+
<rect key="frame" x="48" y="30" width="33" height="34"/>
29+
</imageView>
4630
<stackView opaque="NO" contentMode="scaleToFill" misplaced="YES" axis="vertical" distribution="fillProportionally" alignment="top" translatesAutoresizingMaskIntoConstraints="NO" id="cJi-r8-oeb">
47-
<rect key="frame" x="60" y="29" width="408" height="37"/>
31+
<rect key="frame" x="91" y="28" width="377" height="37"/>
4832
<subviews>
4933
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="751" misplaced="YES" text="[Title]" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IWB-BS-FgD">
5034
<rect key="frame" x="0.0" y="0.0" width="46" height="20"/>
@@ -105,7 +89,6 @@
10589
<outlet property="bodyLabel" destination="gMT-Vh-S3z" id="BkZ-P0-0dh"/>
10690
<outlet property="button" destination="VUM-rq-TVm" id="7RH-Cf-FAH"/>
10791
<outlet property="contentView" destination="RJH-Fp-YDa" id="2Eb-fy-uEf"/>
108-
<outlet property="iconContainer" destination="cFe-Hg-5FF" id="cGw-VP-Ben"/>
10992
<outlet property="iconImageView" destination="eGt-Nj-7Fu" id="N4v-CG-mEM"/>
11093
<outlet property="iconLabel" destination="pFx-Py-lZQ" id="xKK-gA-Otu"/>
11194
<outlet property="titleLabel" destination="IWB-BS-FgD" id="ZFQ-sh-fDL"/>

0 commit comments

Comments
 (0)