add badges

This commit is contained in:
Eugene Pravda 2016-09-28 17:50:32 +03:00
parent 6eee837927
commit 621957e338
4 changed files with 28 additions and 137 deletions

View File

@ -12,6 +12,8 @@
124C21C2A8B015C1BB87D30F4EEA0214 /* SegmentioCellWithImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = F42697752DA8A65CBAB3CC0BB442A8C6 /* SegmentioCellWithImage.swift */; };
1B164D4FADAAAD401CDAFB8541C7AC00 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEC22C73C1608DFA5D5D78BDCB218219 /* Foundation.framework */; };
386B142514D75786C9544322094E00BB /* Pods-Segmentio_Tests-umbrella.h in Headers */ = {isa = PBXBuildFile; fileRef = 7F52E8E5326A4E61091A05424A66750B /* Pods-Segmentio_Tests-umbrella.h */; settings = {ATTRIBUTES = (Public, ); }; };
4482DBD41D9C1019004FA9FF /* BadgeViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4482DBCF1D9C1019004FA9FF /* BadgeViewPresenter.swift */; };
4482DBD51D9C1019004FA9FF /* BadgeWithCounterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4482DBD11D9C1019004FA9FF /* BadgeWithCounterView.swift */; };
5DE5F4B816F4E062B3C9278607C5E632 /* SegmentioCellWithImageUnderLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC4EC586E74DCFF8232A11FFEA0592BC /* SegmentioCellWithImageUnderLabel.swift */; };
639A4D6A5BD89BFDD5ED7603F1D18262 /* SegmentioCellWithImageOverLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D491E2303B96AB5AB9AACDBDD0D96BA1 /* SegmentioCellWithImageOverLabel.swift */; };
7535676B6DAAED27C9E51F128BA31498 /* SegmentioOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1E1181660922799D84A9AC7A93E4C17 /* SegmentioOptions.swift */; };
@ -47,6 +49,10 @@
2C6B3BD660EA40765EA46F0735002B06 /* Pods_Segmentio_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Segmentio_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
401FE729B830FF723B647781804D1F85 /* Pods-Segmentio_Example-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "Pods-Segmentio_Example-umbrella.h"; sourceTree = "<group>"; };
419FF94288A2110D00FAA1CE571FE9FC /* Pods-Segmentio_Example-frameworks.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-Segmentio_Example-frameworks.sh"; sourceTree = "<group>"; };
4482DBCF1D9C1019004FA9FF /* BadgeViewPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BadgeViewPresenter.swift; sourceTree = "<group>"; };
4482DBD11D9C1019004FA9FF /* BadgeWithCounterView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BadgeWithCounterView.swift; sourceTree = "<group>"; };
4482DBD21D9C1019004FA9FF /* BadgeWithCounterViewBigSized.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BadgeWithCounterViewBigSized.xib; sourceTree = "<group>"; };
4482DBD31D9C1019004FA9FF /* BadgeWithCounterViewStandardSized.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BadgeWithCounterViewStandardSized.xib; sourceTree = "<group>"; };
4938DA306399C05E56EDBA62544340BE /* Pods-Segmentio_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-Segmentio_Tests.debug.xcconfig"; sourceTree = "<group>"; };
556AA0B62BF4398859D56C7F281F05FD /* Pods-Segmentio_Example-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-Segmentio_Example-dummy.m"; sourceTree = "<group>"; };
5720677F504FDAE0BB2FF236B2A89893 /* Segmentio-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Segmentio-dummy.m"; sourceTree = "<group>"; };
@ -137,6 +143,25 @@
name = iOS;
sourceTree = "<group>";
};
4482DBCE1D9C1019004FA9FF /* Badge */ = {
isa = PBXGroup;
children = (
4482DBCF1D9C1019004FA9FF /* BadgeViewPresenter.swift */,
4482DBD01D9C1019004FA9FF /* Views */,
);
path = Badge;
sourceTree = "<group>";
};
4482DBD01D9C1019004FA9FF /* Views */ = {
isa = PBXGroup;
children = (
4482DBD11D9C1019004FA9FF /* BadgeWithCounterView.swift */,
4482DBD21D9C1019004FA9FF /* BadgeWithCounterViewBigSized.xib */,
4482DBD31D9C1019004FA9FF /* BadgeWithCounterViewStandardSized.xib */,
);
path = Views;
sourceTree = "<group>";
};
47DD221E11AD5E3ABBE22D1B01521963 /* Extensions */ = {
isa = PBXGroup;
children = (
@ -260,6 +285,7 @@
8D794DA325FA95310FAD589F0A6A3BC8 /* Segmentio.swift */,
E1E1181660922799D84A9AC7A93E4C17 /* SegmentioOptions.swift */,
6A17966A17091F11F4DC34B63A2A4ED4 /* Cells */,
4482DBCE1D9C1019004FA9FF /* Badge */,
47DD221E11AD5E3ABBE22D1B01521963 /* Extensions */,
);
path = Source;
@ -400,7 +426,9 @@
C5C3FE3FCC48A1460787D130DF0CF12E /* Segmentio.swift in Sources */,
7535676B6DAAED27C9E51F128BA31498 /* SegmentioOptions.swift in Sources */,
08F3ADCD6D2B9007082089826E712007 /* UIView+Appearance.swift in Sources */,
4482DBD51D9C1019004FA9FF /* BadgeWithCounterView.swift in Sources */,
E15160B05BBD4763B9DD87EAFA105B3B /* SegmentioCell.swift in Sources */,
4482DBD41D9C1019004FA9FF /* BadgeViewPresenter.swift in Sources */,
124C21C2A8B015C1BB87D30F4EEA0214 /* SegmentioCellWithImage.swift in Sources */,
8B2E8009B9692DF362678E6FE094A084 /* SegmentioCellWithImageAfterLabel.swift in Sources */,
DC7CDA37564D49D1443EFF857FB8B794 /* SegmentioCellWithImageBeforeLabel.swift in Sources */,

View File

@ -1,41 +0,0 @@
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
}
}

View File

@ -1,48 +0,0 @@
<?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>

View File

@ -1,48 +0,0 @@
<?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>