1. Update example.

2. Add actionTextFont property.
This commit is contained in:
zekunyan
2016-02-25 20:47:03 +08:00
parent f5e3c7212d
commit 1e7253cdc5
4 changed files with 26 additions and 36 deletions

View File

@@ -14,7 +14,7 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C6F2623F8CDE60E21644149A"
BlueprintIdentifier = "19F7F019C1EA89B6CEA56DC59E46C5C7"
BuildableName = "TTGSnackbar.framework"
BlueprintName = "TTGSnackbar"
ReferencedContainer = "container:Pods.xcodeproj">

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8191" systemVersion="15A284" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
@@ -20,7 +20,6 @@
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="TTGSnackbar Example" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xBW-Zw-kpc">
<rect key="frame" x="8" y="28" width="304" height="40"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="40" id="q3q-ER-KUd"/>
</constraints>
@@ -30,7 +29,6 @@
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="TTGSnackbar !" borderStyle="roundedRect" placeholder="Input message..." textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Nw8-uo-Ei8">
<rect key="frame" x="96" y="101" width="216" height="30"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="30" id="oP6-hf-cag"/>
</constraints>
@@ -39,7 +37,6 @@
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JLn-te-FrQ">
<rect key="frame" x="8" y="299" width="304" height="30"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="30" id="Iub-7C-VUR"/>
</constraints>
@@ -50,7 +47,6 @@
</button>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="Qmo-pb-1Vr">
<rect key="frame" x="96" y="139" width="216" height="29"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="28" id="FL2-7Q-li9"/>
</constraints>
@@ -62,7 +58,6 @@
</segmentedControl>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Message:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rL7-Tw-8qy">
<rect key="frame" x="8" y="105" width="80" height="21"/>
<animations/>
<constraints>
<constraint firstAttribute="width" constant="80" id="4tB-F0-itg"/>
<constraint firstAttribute="height" constant="21" id="9Zv-5Z-s5b"/>
@@ -71,9 +66,8 @@
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="Action !" borderStyle="roundedRect" placeholder="Input action title..." textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="3zb-N3-T0U">
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="Cancel" borderStyle="roundedRect" placeholder="Input action title..." textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="3zb-N3-T0U">
<rect key="frame" x="96" y="175" width="216" height="30"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="30" id="xwb-Vu-9Rf"/>
</constraints>
@@ -82,7 +76,6 @@
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Duration:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="PWv-fU-xTM">
<rect key="frame" x="8" y="142" width="80" height="21"/>
<animations/>
<constraints>
<constraint firstAttribute="width" constant="80" id="bcW-3g-HBl"/>
<constraint firstAttribute="height" constant="21" id="mDy-91-kdV"/>
@@ -93,7 +86,6 @@
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="T0P-ip-8Ax">
<rect key="frame" x="8" y="337" width="304" height="30"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="30" id="DdY-Rd-qK9"/>
</constraints>
@@ -104,7 +96,6 @@
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Action:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Dc8-QX-iBM">
<rect key="frame" x="8" y="179" width="80" height="21"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="21" id="5qc-68-B4s"/>
<constraint firstAttribute="width" constant="80" id="hli-X3-KTi"/>
@@ -115,7 +106,6 @@
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Animation:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="JjI-kO-2a8">
<rect key="frame" x="8" y="216" width="80" height="21"/>
<animations/>
<constraints>
<constraint firstAttribute="width" constant="80" id="cRS-nM-hbC"/>
<constraint firstAttribute="height" constant="21" id="vwi-rD-May"/>
@@ -126,7 +116,6 @@
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="27G-2R-7Jg">
<rect key="frame" x="8" y="375" width="304" height="30"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="30" id="PnL-Nj-whO"/>
</constraints>
@@ -137,7 +126,6 @@
</button>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" apportionsSegmentWidthsByContent="YES" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="GaD-qt-sQn">
<rect key="frame" x="96" y="213" width="220" height="29"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="28" id="8SS-If-wBa"/>
</constraints>
@@ -150,7 +138,6 @@
</segmentedControl>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Output:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2rD-KP-VmZ">
<rect key="frame" x="8" y="253" width="80" height="21"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="21" id="q4q-tN-oi3"/>
<constraint firstAttribute="width" constant="80" id="xo3-M6-468"/>
@@ -161,7 +148,6 @@
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fAa-hC-Qfs">
<rect key="frame" x="96" y="249" width="216" height="30"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="30" id="bme-B4-sOE"/>
</constraints>
@@ -170,7 +156,6 @@
<nil key="highlightedColor"/>
</label>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="rL7-Tw-8qy" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" constant="-8" id="27X-Tk-znM"/>

View File

@@ -25,6 +25,11 @@ class ViewController: UIViewController {
@IBAction func show(sender: UIButton) {
let snackbar: TTGSnackbar = TTGSnackbar.init(message: messageTextField.text!, duration: durationTypes[durationSegmented.selectedSegmentIndex])
// Change message text font and color
snackbar.messageTextColor = UIColor.yellowColor()
snackbar.messageTextFont = UIFont.boldSystemFontOfSize(18)
snackbar.animationType = animationTypes[animationTypeSegmented!.selectedSegmentIndex]
snackbar.show()
}
@@ -34,8 +39,9 @@ class ViewController: UIViewController {
let snackbar: TTGSnackbar = TTGSnackbar.init(message: messageTextField.text!, duration: durationTypes[durationSegmented.selectedSegmentIndex],
actionText: actionTextField.text!, actionBlock: { (TTGSnackbar snackbar) in self.outputLabel?.text = "Click action !" })
// Change message text color
snackbar.messageTextColor = UIColor.yellowColor()
// Change action text font and color
snackbar.actionTextColor = UIColor.grayColor()
snackbar.actionTextFont = UIFont.italicSystemFontOfSize(16)
snackbar.animationType = animationTypes[animationTypeSegmented!.selectedSegmentIndex]
snackbar.show()
@@ -58,9 +64,6 @@ class ViewController: UIViewController {
snackbar.dismissBlock = {
(snackbar: TTGSnackbar) -> Void in self.outputLabel?.text = "Dismiss !"
}
// Change action text color
snackbar.actionTextColor = UIColor.yellowColor()
snackbar.animationType = animationTypes[animationTypeSegmented!.selectedSegmentIndex]
snackbar.show()

View File

@@ -130,6 +130,13 @@ public class TTGSnackbar: UIView {
actionButton.setTitleColor(actionTextColor, forState: UIControlState.Normal)
}
}
/// Action text font. Default is Bold system font (14).
public dynamic var actionTextFont: UIFont = UIFont.boldSystemFontOfSize(14) {
didSet {
self.actionButton.titleLabel?.font = actionTextFont
}
}
// MARK: -
// MARK: Private property.
@@ -196,13 +203,15 @@ public class TTGSnackbar: UIView {
- returns: Void
*/
public init(message: String, duration: TTGSnackbarDuration, actionText: String, messageFont: UIFont, actionButtonFont: UIFont, actionBlock: TTGActionBlock) {
public init(message: String, duration: TTGSnackbarDuration, actionText: String, messageFont: UIFont, actionTextFont: UIFont, actionBlock: TTGActionBlock) {
super.init(frame: CGRectMake(0, 0, 0, 0))
self.duration = duration
self.message = message
self.actionText = actionText
self.actionBlock = actionBlock
configure(messageFont, actionButtonFont: actionButtonFont)
self.messageTextFont = messageFont
self.actionTextFont = actionTextFont
configure()
}
public required init?(coder aDecoder: NSCoder) {
@@ -271,17 +280,10 @@ public class TTGSnackbar: UIView {
// MARK: -
// MARK: Private methods.
/**
Default init configuration.
*/
private func configure() {
self.configure(UIFont.systemFontOfSize(14), actionButtonFont: UIFont.boldSystemFontOfSize(14))
}
/**
Init configuration.
*/
private func configure(messageFont: UIFont, actionButtonFont: UIFont) {
private func configure() {
self.translatesAutoresizingMaskIntoConstraints = false
self.backgroundColor = UIColor.init(white: 0, alpha: 0.8)
self.layer.cornerRadius = 4
@@ -290,7 +292,7 @@ public class TTGSnackbar: UIView {
messageLabel = UILabel()
messageLabel.translatesAutoresizingMaskIntoConstraints = false
messageLabel.textColor = UIColor.whiteColor()
messageLabel.font = messageFont
messageLabel.font = messageTextFont
messageLabel.backgroundColor = UIColor.clearColor()
messageLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
messageLabel.numberOfLines = 2
@@ -301,7 +303,7 @@ public class TTGSnackbar: UIView {
actionButton = UIButton()
actionButton.translatesAutoresizingMaskIntoConstraints = false
actionButton.backgroundColor = UIColor.clearColor()
actionButton.titleLabel?.font = actionButtonFont
actionButton.titleLabel?.font = actionTextFont
actionButton.setTitle(actionText, forState: UIControlState.Normal)
actionButton.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
actionButton.addTarget(self, action: Selector("doAction"), forControlEvents: UIControlEvents.TouchUpInside)