update constraints
This commit is contained in:
parent
0a537b62d9
commit
6eee837927
|
|
@ -48,6 +48,7 @@ class ExampleViewController: UIViewController {
|
|||
super.viewDidAppear(animated)
|
||||
setupSegmentioView()
|
||||
setupScrollView()
|
||||
setupBadgeCountForIndex()
|
||||
}
|
||||
|
||||
private func setupSegmentioView() {
|
||||
|
|
@ -70,6 +71,10 @@ class ExampleViewController: UIViewController {
|
|||
}
|
||||
}
|
||||
|
||||
private func setupBadgeCountForIndex() {
|
||||
segmentioView.setupBadgeAtIndex(1, count: 3, color: ColorPalette.WhiteSmokeColor)
|
||||
}
|
||||
|
||||
private func segmentioContent() -> [SegmentioItem] {
|
||||
return [
|
||||
SegmentioItem(title: "Tornado", image: UIImage(named: "tornado")),
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ Pod::Spec.new do |spec|
|
|||
spec.source = { :git => "https://github.com/Yalantis/Segmentio.git", :tag => spec.version }
|
||||
|
||||
spec.source_files = 'Segmentio/Source/**/*.swift'
|
||||
spec.source_files.resource_bundles = {
|
||||
'Segmentio' => ['Pod/**/*.{storyboard,xib,xcassets,json,imageset,png}']
|
||||
}
|
||||
spec.module_name = 'Segmentio'
|
||||
spec.requires_arc = true
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,88 @@
|
|||
//
|
||||
// BadgeViewPresenter.swift
|
||||
// Pods
|
||||
//
|
||||
// Created by Eugene on 22.09.16.
|
||||
//
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class BadgeViewPresenter {
|
||||
|
||||
func addBadgeForContainerView(
|
||||
containerView: UIView,
|
||||
counterValue: Int,
|
||||
backgroundColor: UIColor = .redColor(),
|
||||
badgeSize: CounterBadgeSize = .Standard
|
||||
) {
|
||||
var badgeView: BadgeWithCounterView?
|
||||
for view in containerView.subviews {
|
||||
if view is BadgeWithCounterView {
|
||||
badgeView = view as! BadgeWithCounterView
|
||||
badgeView?.setBadgeBackgroundColor(backgroundColor)
|
||||
badgeView?.setBadgeCounterValue(counterValue)
|
||||
}
|
||||
}
|
||||
if badgeView == nil {
|
||||
badgeView = badgeViewForCounterValue(
|
||||
counterValue,
|
||||
backgroundColor: backgroundColor,
|
||||
size: badgeSize
|
||||
)
|
||||
containerView.addSubview(badgeView!)
|
||||
setupBadgeConstraints(containerView, badgeView: badgeView!)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func removeBadgeFromContainerView(containerView: UIView) {
|
||||
for view in containerView.subviews {
|
||||
if view is BadgeWithCounterView {
|
||||
view.removeFromSuperview()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func setupBadgeConstraints(containerView: UIView, badgeView: BadgeWithCounterView) {
|
||||
|
||||
let segmentTitleLabelHorizontalCenterConstraint =
|
||||
NSLayoutConstraint(
|
||||
item: badgeView,
|
||||
attribute: .Top,
|
||||
relatedBy: .Equal,
|
||||
toItem: containerView,
|
||||
attribute: .Top,
|
||||
multiplier: 1,
|
||||
constant: 1.0
|
||||
)
|
||||
|
||||
let segmentTitleLabelVerticalCenterConstraint =
|
||||
NSLayoutConstraint(
|
||||
item: badgeView,
|
||||
attribute: .Trailing,
|
||||
relatedBy: .Equal,
|
||||
toItem: containerView,
|
||||
attribute: .Trailing,
|
||||
multiplier: 1,
|
||||
constant: 1.0
|
||||
)
|
||||
containerView.addConstraints([segmentTitleLabelHorizontalCenterConstraint, segmentTitleLabelVerticalCenterConstraint])
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: Badges views creation
|
||||
|
||||
extension BadgeViewPresenter {
|
||||
|
||||
private func badgeViewForCounterValue(counter: Int, backgroundColor: UIColor, size: CounterBadgeSize) -> BadgeWithCounterView {
|
||||
let view = BadgeWithCounterView.instanceFromNib(size: size)
|
||||
view.setBadgeBackgroundColor(backgroundColor)
|
||||
view.setBadgeCounterValue(counter)
|
||||
return view
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
import Foundation
|
||||
|
||||
private let BadgeCounterMaxValue = 99
|
||||
private let BadgeCounterOverMaxValueText = "99+"
|
||||
private let standardSizedNibName = "BadgeWithCounterViewStandardSized"
|
||||
private let bigSizedNibName = "BadgeWithCounterViewBigSized"
|
||||
|
||||
enum CounterBadgeSize {
|
||||
case Standard
|
||||
case Big
|
||||
}
|
||||
|
||||
class BadgeWithCounterView: UIView {
|
||||
|
||||
@IBOutlet private weak var counterValueLabel: UILabel!
|
||||
@IBOutlet private weak var backgroundImageView: UIImageView!
|
||||
|
||||
class func instanceFromNib(size size: CounterBadgeSize) -> BadgeWithCounterView {
|
||||
let nibName = nibNameForSize(size)
|
||||
return UINib(nibName: nibName, bundle: nil).instantiateWithOwner(nil, options: nil)[0] as! BadgeWithCounterView
|
||||
}
|
||||
|
||||
func setBadgeCounterValue(counterValue: Int) {
|
||||
var counterText: String!
|
||||
if counterValue > BadgeCounterMaxValue {
|
||||
counterText = BadgeCounterOverMaxValueText
|
||||
} else {
|
||||
counterText = String(counterValue)
|
||||
}
|
||||
counterValueLabel.text = counterText
|
||||
}
|
||||
|
||||
func setBadgeBackgroundColor(color: UIColor) {
|
||||
backgroundImageView.backgroundColor = color
|
||||
}
|
||||
|
||||
private class func nibNameForSize(size: CounterBadgeSize) -> String {
|
||||
return (size == .Standard) ? standardSizedNibName : bigSizedNibName
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
|
||||
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<view userInteractionEnabled="NO" contentMode="scaleToFill" id="KcE-SS-9TU" customClass="BadgeWithCounterView" customModule="Segmentio">
|
||||
<rect key="frame" x="0.0" y="0.0" width="38" height="20"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="250" verticalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="v0J-W6-cSb" userLabel="Background Image View" customClass="RoundImageView" customModule="BroApp" customModuleProvider="target">
|
||||
<rect key="frame" x="-2" y="-1" width="40.5" height="22"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="20" id="0LH-dc-4RL"/>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" secondItem="v0J-W6-cSb" secondAttribute="height" id="ofE-fK-2Pf"/>
|
||||
</constraints>
|
||||
</imageView>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="1000" verticalHuggingPriority="1000" text="99+" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.30000001192092896" translatesAutoresizingMaskIntoConstraints="NO" id="aLy-ls-VfX" userLabel="Counter Value Label">
|
||||
<rect key="frame" x="6" y="2" width="25" height="16"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="13"/>
|
||||
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstItem="v0J-W6-cSb" firstAttribute="centerX" secondItem="KcE-SS-9TU" secondAttribute="centerX" id="8mG-rK-NDa"/>
|
||||
<constraint firstItem="aLy-ls-VfX" firstAttribute="width" secondItem="v0J-W6-cSb" secondAttribute="width" constant="-15" id="G78-cE-E4C"/>
|
||||
<constraint firstItem="v0J-W6-cSb" firstAttribute="centerY" secondItem="KcE-SS-9TU" secondAttribute="centerY" id="ObE-ZA-xQJ"/>
|
||||
<constraint firstItem="aLy-ls-VfX" firstAttribute="centerX" secondItem="v0J-W6-cSb" secondAttribute="centerX" id="Rvg-Jy-Cnd"/>
|
||||
<constraint firstItem="aLy-ls-VfX" firstAttribute="centerY" secondItem="v0J-W6-cSb" secondAttribute="centerY" id="ibJ-Qo-25e"/>
|
||||
<constraint firstItem="aLy-ls-VfX" firstAttribute="height" secondItem="v0J-W6-cSb" secondAttribute="height" constant="-6" id="kr5-0Q-aUM"/>
|
||||
</constraints>
|
||||
<nil key="simulatedStatusBarMetrics"/>
|
||||
<nil key="simulatedTopBarMetrics"/>
|
||||
<nil key="simulatedBottomBarMetrics"/>
|
||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
<connections>
|
||||
<outlet property="backgroundImageView" destination="v0J-W6-cSb" id="F4i-xu-iDM"/>
|
||||
<outlet property="counterValueLabel" destination="aLy-ls-VfX" id="uv7-Qn-Ucz"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="398" y="446"/>
|
||||
</view>
|
||||
</objects>
|
||||
</document>
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
|
||||
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<view userInteractionEnabled="NO" contentMode="scaleToFill" id="iN0-l3-epB" customClass="BadgeWithCounterView" customModule="Segmentio">
|
||||
<rect key="frame" x="0.0" y="0.0" width="30" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="250" verticalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="d4V-GG-9pR" userLabel="Background Image View" customClass="RoundImageView" customModule="BroApp" customModuleProvider="target">
|
||||
<rect key="frame" x="-2" y="-1" width="32.5" height="20"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="18" id="Nld-O1-MJv"/>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" secondItem="d4V-GG-9pR" secondAttribute="height" id="cCQ-lW-OUm"/>
|
||||
</constraints>
|
||||
</imageView>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="1000" verticalHuggingPriority="1000" text="99+" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.29999999999999999" translatesAutoresizingMaskIntoConstraints="NO" id="ech-Mu-YMM" userLabel="Counter Value Label">
|
||||
<rect key="frame" x="2.5" y="1" width="25" height="16"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="13"/>
|
||||
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstItem="ech-Mu-YMM" firstAttribute="centerY" secondItem="d4V-GG-9pR" secondAttribute="centerY" id="3TE-QX-wNX"/>
|
||||
<constraint firstItem="ech-Mu-YMM" firstAttribute="centerX" secondItem="d4V-GG-9pR" secondAttribute="centerX" id="QJJ-ap-dbB"/>
|
||||
<constraint firstItem="d4V-GG-9pR" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="R7x-Ll-s8y"/>
|
||||
<constraint firstItem="ech-Mu-YMM" firstAttribute="width" secondItem="d4V-GG-9pR" secondAttribute="width" constant="-7" id="Sz2-qr-fOS"/>
|
||||
<constraint firstItem="d4V-GG-9pR" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="dFc-74-PeR"/>
|
||||
<constraint firstItem="ech-Mu-YMM" firstAttribute="height" secondItem="d4V-GG-9pR" secondAttribute="height" constant="-4" id="uDs-Tl-0La"/>
|
||||
</constraints>
|
||||
<nil key="simulatedStatusBarMetrics"/>
|
||||
<nil key="simulatedTopBarMetrics"/>
|
||||
<nil key="simulatedBottomBarMetrics"/>
|
||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
<connections>
|
||||
<outlet property="backgroundImageView" destination="d4V-GG-9pR" id="aJr-t4-PcZ"/>
|
||||
<outlet property="counterValueLabel" destination="ech-Mu-YMM" id="7r3-jp-rZj"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="398" y="446"/>
|
||||
</view>
|
||||
</objects>
|
||||
</document>
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
import Foundation
|
||||
|
||||
private let BadgeCounterMaxValue = 99
|
||||
private let BadgeCounterOverMaxValueText = "99+"
|
||||
private let standardSizedNibName = "BadgeWithCounterViewStandardSized"
|
||||
private let bigSizedNibName = "BadgeWithCounterViewBigSized"
|
||||
|
||||
enum CounterBadgeSize {
|
||||
case Standard
|
||||
case Big
|
||||
}
|
||||
|
||||
class BadgeWithCounterView: UIView {
|
||||
|
||||
@IBOutlet private weak var counterValueLabel: UILabel!
|
||||
@IBOutlet private weak var backgroundImageView: UIImageView!
|
||||
|
||||
class func instanceFromNib(size size: CounterBadgeSize) -> BadgeWithCounterView {
|
||||
let nibName = nibNameForSize(size)
|
||||
return UINib(nibName: nibName, bundle: nil).instantiateWithOwner(nil, options: nil)[0] as! BadgeWithCounterView
|
||||
}
|
||||
|
||||
func setBadgeCounterValue(counterValue: Int) {
|
||||
var counterText: String!
|
||||
if counterValue > BadgeCounterMaxValue {
|
||||
counterText = BadgeCounterOverMaxValueText
|
||||
} else {
|
||||
counterText = String(counterValue)
|
||||
}
|
||||
counterValueLabel.text = counterText
|
||||
}
|
||||
|
||||
func setBadgeBackgroundColor(color: UIColor) {
|
||||
backgroundImageView.backgroundColor = color
|
||||
}
|
||||
|
||||
private class func nibNameForSize(size: CounterBadgeSize) -> String {
|
||||
return (size == .Standard) ? standardSizedNibName : bigSizedNibName
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
|
||||
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<view userInteractionEnabled="NO" contentMode="scaleToFill" id="KcE-SS-9TU" customClass="BroBadgeWithCounterView" customModule="BroApp" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="38" height="20"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="250" verticalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="v0J-W6-cSb" userLabel="Background Image View" customClass="RoundImageView" customModule="BroApp" customModuleProvider="target">
|
||||
<rect key="frame" x="-2" y="-1" width="40.5" height="22"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="20" id="0LH-dc-4RL"/>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" secondItem="v0J-W6-cSb" secondAttribute="height" id="ofE-fK-2Pf"/>
|
||||
</constraints>
|
||||
</imageView>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="1000" verticalHuggingPriority="1000" text="99+" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.30000001192092896" translatesAutoresizingMaskIntoConstraints="NO" id="aLy-ls-VfX" userLabel="Counter Value Label">
|
||||
<rect key="frame" x="6" y="2" width="25" height="16"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="13"/>
|
||||
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstItem="v0J-W6-cSb" firstAttribute="centerX" secondItem="KcE-SS-9TU" secondAttribute="centerX" id="8mG-rK-NDa"/>
|
||||
<constraint firstItem="aLy-ls-VfX" firstAttribute="width" secondItem="v0J-W6-cSb" secondAttribute="width" constant="-15" id="G78-cE-E4C"/>
|
||||
<constraint firstItem="v0J-W6-cSb" firstAttribute="centerY" secondItem="KcE-SS-9TU" secondAttribute="centerY" id="ObE-ZA-xQJ"/>
|
||||
<constraint firstItem="aLy-ls-VfX" firstAttribute="centerX" secondItem="v0J-W6-cSb" secondAttribute="centerX" id="Rvg-Jy-Cnd"/>
|
||||
<constraint firstItem="aLy-ls-VfX" firstAttribute="centerY" secondItem="v0J-W6-cSb" secondAttribute="centerY" id="ibJ-Qo-25e"/>
|
||||
<constraint firstItem="aLy-ls-VfX" firstAttribute="height" secondItem="v0J-W6-cSb" secondAttribute="height" constant="-6" id="kr5-0Q-aUM"/>
|
||||
</constraints>
|
||||
<nil key="simulatedStatusBarMetrics"/>
|
||||
<nil key="simulatedTopBarMetrics"/>
|
||||
<nil key="simulatedBottomBarMetrics"/>
|
||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
<connections>
|
||||
<outlet property="backgroundImageView" destination="v0J-W6-cSb" id="F4i-xu-iDM"/>
|
||||
<outlet property="counterValueLabel" destination="aLy-ls-VfX" id="uv7-Qn-Ucz"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="398" y="446"/>
|
||||
</view>
|
||||
</objects>
|
||||
</document>
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
|
||||
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<view userInteractionEnabled="NO" contentMode="scaleToFill" id="iN0-l3-epB" customClass="BroBadgeWithCounterView" customModule="BroApp" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="30" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="250" verticalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="d4V-GG-9pR" userLabel="Background Image View" customClass="RoundImageView" customModule="BroApp" customModuleProvider="target">
|
||||
<rect key="frame" x="-2" y="-1" width="32.5" height="20"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="18" id="Nld-O1-MJv"/>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" secondItem="d4V-GG-9pR" secondAttribute="height" id="cCQ-lW-OUm"/>
|
||||
</constraints>
|
||||
</imageView>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="1000" verticalHuggingPriority="1000" text="99+" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.29999999999999999" translatesAutoresizingMaskIntoConstraints="NO" id="ech-Mu-YMM" userLabel="Counter Value Label">
|
||||
<rect key="frame" x="2.5" y="1" width="25" height="16"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="13"/>
|
||||
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstItem="ech-Mu-YMM" firstAttribute="centerY" secondItem="d4V-GG-9pR" secondAttribute="centerY" id="3TE-QX-wNX"/>
|
||||
<constraint firstItem="ech-Mu-YMM" firstAttribute="centerX" secondItem="d4V-GG-9pR" secondAttribute="centerX" id="QJJ-ap-dbB"/>
|
||||
<constraint firstItem="d4V-GG-9pR" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="R7x-Ll-s8y"/>
|
||||
<constraint firstItem="ech-Mu-YMM" firstAttribute="width" secondItem="d4V-GG-9pR" secondAttribute="width" constant="-7" id="Sz2-qr-fOS"/>
|
||||
<constraint firstItem="d4V-GG-9pR" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="dFc-74-PeR"/>
|
||||
<constraint firstItem="ech-Mu-YMM" firstAttribute="height" secondItem="d4V-GG-9pR" secondAttribute="height" constant="-4" id="uDs-Tl-0La"/>
|
||||
</constraints>
|
||||
<nil key="simulatedStatusBarMetrics"/>
|
||||
<nil key="simulatedTopBarMetrics"/>
|
||||
<nil key="simulatedBottomBarMetrics"/>
|
||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
<connections>
|
||||
<outlet property="backgroundImageView" destination="d4V-GG-9pR" id="aJr-t4-PcZ"/>
|
||||
<outlet property="counterValueLabel" destination="ech-Mu-YMM" id="7r3-jp-rZj"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="398" y="446"/>
|
||||
</view>
|
||||
</objects>
|
||||
</document>
|
||||
|
|
@ -25,6 +25,7 @@ class SegmentioCell: UICollectionViewCell {
|
|||
private var options = SegmentioOptions()
|
||||
private var style = SegmentioStyle.ImageOverLabel
|
||||
private let verticalSeparatorLayer = CAShapeLayer()
|
||||
private let badgePresenter = BadgeViewPresenter()
|
||||
|
||||
override var highlighted: Bool {
|
||||
get {
|
||||
|
|
@ -71,7 +72,7 @@ class SegmentioCell: UICollectionViewCell {
|
|||
if let segmentTitleLabel = segmentTitleLabel, containerView = containerView {
|
||||
containerView.addSubview(segmentTitleLabel)
|
||||
}
|
||||
|
||||
|
||||
segmentImageView?.translatesAutoresizingMaskIntoConstraints = false
|
||||
segmentTitleLabel?.translatesAutoresizingMaskIntoConstraints = false
|
||||
containerView?.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
|
@ -80,7 +81,6 @@ class SegmentioCell: UICollectionViewCell {
|
|||
segmentTitleLabel?.font = UIFont.systemFontOfSize(UIFont.smallSystemFontSize())
|
||||
|
||||
setupConstraintsForSubviews()
|
||||
setupContainerConstraints()
|
||||
addVerticalSeparator()
|
||||
}
|
||||
|
||||
|
|
@ -109,7 +109,6 @@ class SegmentioCell: UICollectionViewCell {
|
|||
self.options = options
|
||||
self.style = style
|
||||
setupContent(content: content)
|
||||
|
||||
if let indicatorOptions = self.options.indicatorOptions {
|
||||
setupConstraint(indicatorOptions: indicatorOptions)
|
||||
}
|
||||
|
|
@ -133,13 +132,36 @@ class SegmentioCell: UICollectionViewCell {
|
|||
}
|
||||
}
|
||||
|
||||
func setupConstraintsForSubviews() {
|
||||
return // implement in subclasses
|
||||
func configurateBadgeWithCount(badgeCount: Int?, color: UIColor?) {
|
||||
guard let badgeCount = badgeCount, color = color else {
|
||||
return
|
||||
}
|
||||
|
||||
if style == .OnlyImage {
|
||||
badgePresenter.addBadgeForContainerView(
|
||||
segmentImageView!,
|
||||
counterValue: badgeCount,
|
||||
backgroundColor: color,
|
||||
badgeSize: .Standard
|
||||
)
|
||||
} else {
|
||||
badgePresenter.addBadgeForContainerView(
|
||||
containerView!,
|
||||
counterValue: badgeCount,
|
||||
backgroundColor: color,
|
||||
badgeSize: .Standard
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func setupConstraintsForSubviews() {
|
||||
setupContainerConstraints()
|
||||
return // implement in subclasses
|
||||
}
|
||||
|
||||
// MARK: - Private functions
|
||||
|
||||
func setupContainerConstraints() {
|
||||
private func setupContainerConstraints() {
|
||||
guard let segmentTitleLabel = segmentTitleLabel else {
|
||||
return
|
||||
}
|
||||
|
|
@ -168,7 +190,6 @@ class SegmentioCell: UICollectionViewCell {
|
|||
multiplier: 1,
|
||||
constant: 0.0
|
||||
)
|
||||
|
||||
addConstraints([segmentTitleLabelHorizontalCenterConstraint, segmentTitleLabelVerticalCenterConstraint])
|
||||
}
|
||||
|
||||
|
|
@ -185,7 +206,7 @@ class SegmentioCell: UICollectionViewCell {
|
|||
segmentTitleLabel?.font = defaultState.titleFont
|
||||
segmentTitleLabel?.text = content.title
|
||||
}
|
||||
configurateBadgeWithCount(content.badgeCount)
|
||||
configurateBadgeWithCount(content.badgeCount, color: content.badgeColor)
|
||||
}
|
||||
|
||||
private func setupConstraint(indicatorOptions indicatorOptions: SegmentioIndicatorOptions) {
|
||||
|
|
@ -196,13 +217,7 @@ class SegmentioCell: UICollectionViewCell {
|
|||
bottomConstraint?.constant = padding + indicatorOptions.height
|
||||
}
|
||||
}
|
||||
|
||||
private func configurateBadgeWithCount(count: Int?) {
|
||||
if let count = count {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Vertical separator
|
||||
|
||||
private func addVerticalSeparator() {
|
||||
|
|
@ -253,8 +268,10 @@ class SegmentioCell: UICollectionViewCell {
|
|||
|
||||
let topConstraint = NSLayoutConstraint(
|
||||
item: verticalSeparatorView,
|
||||
attribute: .Top, relatedBy: .Equal,
|
||||
toItem: contentView, attribute: .Top,
|
||||
attribute: .Top,
|
||||
relatedBy: .Equal,
|
||||
toItem: contentView,
|
||||
attribute: .Top,
|
||||
multiplier: 1,
|
||||
constant: 0
|
||||
)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import UIKit
|
|||
final class SegmentioCellWithImageAfterLabel: SegmentioCell {
|
||||
|
||||
override func setupConstraintsForSubviews() {
|
||||
super.setupConstraintsForSubviews()
|
||||
guard let segmentImageView = segmentImageView else {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import UIKit
|
|||
class SegmentioCellWithImageBeforeLabel: SegmentioCell {
|
||||
|
||||
override func setupConstraintsForSubviews() {
|
||||
super.setupConstraintsForSubviews()
|
||||
guard let segmentImageView = segmentImageView else {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import UIKit
|
|||
class SegmentioCellWithImageOverLabel: SegmentioCell {
|
||||
|
||||
override func setupConstraintsForSubviews() {
|
||||
super.setupConstraintsForSubviews()
|
||||
guard let segmentImageView = segmentImageView else {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import UIKit
|
|||
class SegmentioCellWithImageUnderLabel: SegmentioCell {
|
||||
|
||||
override func setupConstraintsForSubviews() {
|
||||
super.setupConstraintsForSubviews()
|
||||
guard let segmentImageView = segmentImageView else {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,11 @@ import UIKit
|
|||
final class SegmentioCellWithLabel: SegmentioCell {
|
||||
|
||||
override func setupConstraintsForSubviews() {
|
||||
super.setupConstraintsForSubviews()
|
||||
|
||||
guard let segmentTitleLabel = segmentTitleLabel else {
|
||||
return
|
||||
}
|
||||
|
||||
guard let containerView = containerView else {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
import Foundation
|
||||
|
||||
@IBDesignable
|
||||
class RoundImageView: UIImageView {
|
||||
|
||||
override var bounds: CGRect {
|
||||
didSet {
|
||||
updateCornerRadiusValue()
|
||||
}
|
||||
}
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
|
||||
updateCornerRadiusValue()
|
||||
}
|
||||
|
||||
private func updateCornerRadiusValue() {
|
||||
let cornerRadius = min(bounds.size.height, bounds.size.width) / 2
|
||||
layer.cornerRadius = cornerRadius
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -203,7 +203,7 @@ public class Segmentio: UIView {
|
|||
setupHorizontalSeparatorIfPossible()
|
||||
}
|
||||
|
||||
public func setupBadgeAtIndex(index: Int, count: Int, image: UIImage) {
|
||||
public func setupBadgeAtIndex(index: Int, count: Int, color: UIColor) {
|
||||
segmentioItems[index].setupBadgeWithCount(count)
|
||||
segmentioCollectionView?.reloadData()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,14 +14,16 @@ public struct SegmentioItem {
|
|||
var title: String?
|
||||
var image: UIImage?
|
||||
var badgeCount: Int?
|
||||
var badgeColor: UIColor?
|
||||
|
||||
public init(title: String?, image: UIImage?) {
|
||||
self.title = title
|
||||
self.image = image
|
||||
}
|
||||
|
||||
public mutating func setupBadgeWithCount(count: Int) {
|
||||
public mutating func setupBadgeWithCount(count: Int, color: UIColor = .redColor()) {
|
||||
self.badgeCount = count
|
||||
self.badgeColor = color
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue