Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tutorial #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions BadgeHub/Classes/BadgeHub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,19 @@ public class BadgeHub: NSObject {
setView(view, andCount: 0)
}

// convenience init(barButtonItem: UIBarButtonItem?) {
// if let value = barButtonItem?.value(forKey: "view") as? UIView {
// self.init(view: value)
// scaleCircleSize(by: 0.7)
// moveCircleBy(x: -5.0, y: 0)
// }
// }
public convenience init?(barButtonItem: UIBarButtonItem) {
if let value = barButtonItem.value(forKey: "view") as? UIView {
self.init(view: value)
scaleCircleSize(by: 0.7)
moveCircleBy(x: -5.0, y: 0)
} else if let value = barButtonItem.customView {
self.init(view: value)
scaleCircleSize(by: 0.7)
moveCircleBy(x: -5.0, y: 0)
} else {
return nil
}
}

// Adjustment methods
public func setView(_ view: UIView?, andCount startCount: Int) {
Expand Down
90 changes: 45 additions & 45 deletions Example/BadgeHub.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

32 changes: 27 additions & 5 deletions Example/BadgeHub/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14868" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="NTb-fB-oE5">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14824"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -22,9 +20,33 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<navigationItem key="navigationItem" id="bBy-7s-jsq">
<barButtonItem key="rightBarButtonItem" title="Item" id="ach-RU-RNK"/>
</navigationItem>
<connections>
<outlet property="barItem" destination="ach-RU-RNK" id="tSB-hj-FbS"/>
<outlet property="navigationItem" destination="bBy-7s-jsq" id="zwu-av-5ue"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="138" y="134"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="no8-NT-Qbg">
<objects>
<navigationController id="NTb-fB-oE5" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="ccQ-jY-H8G">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="vXZ-lx-hvc" kind="relationship" relationship="rootViewController" id="bkg-px-V5O"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="nrg-ux-5l3" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-994" y="188"/>
</scene>
</scenes>
</document>
20 changes: 15 additions & 5 deletions Example/BadgeHub/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ import UIKit
class ViewController: UIViewController {

private var hub: BadgeHub?

var hub2: BadgeHub?

@IBOutlet weak var barItem: UIBarButtonItem!

override func viewDidLoad() {
super.viewDidLoad()

setupButton()
setupImageView()
setupBarButtomItem()
}

func setupButton() {
let color = UIColor(red: 255/255, green: 47/255, blue: 146/255, alpha: 1)

let button = UIButton(frame: CGRect(x: view.frame.size.width / 2 - 75, y: 200, width: 150, height: 44))
let navigationHeight: CGFloat = self.navigationController?.navigationBar.frame.size.height ?? 0
let button = UIButton(frame: CGRect(x: view.frame.size.width / 2 - 75, y: 200 + navigationHeight, width: 150, height: 44))
button.setTitleColor(UIColor.white, for: .normal)
button.setTitle("Increment", for: .normal)
button.backgroundColor = color
Expand All @@ -34,18 +38,24 @@ class ViewController: UIViewController {

func setupImageView() {
let imageView = UIImageView(image: UIImage(named: "github_color"))
imageView.frame = CGRect(x: view.frame.size.width / 2 - 48, y: 80, width: 96, height: 96)
let navigationHeight: CGFloat = self.navigationController?.navigationBar.frame.size.height ?? 0
imageView.frame = CGRect(x: view.frame.size.width / 2 - 48, y: 80 + navigationHeight, width: 96, height: 96)

hub = BadgeHub(view: imageView)
hub?.moveCircleBy(x: -15, y: 15)

view.addSubview(imageView)
}

func setupBarButtomItem(){
hub2 = BadgeHub(barButtonItem: barItem)
}

@objc func testIncrement() {
hub2?.increment()
hub2?.pop()
hub?.increment()
hub?.pop()
}

}

2 changes: 1 addition & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: c0e9ea82a511c7b3c636576ece9097ef9cc2e1ab

COCOAPODS: 1.7.1
COCOAPODS: 1.7.5
2 changes: 1 addition & 1 deletion Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading