Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
599EFBF824603EE00079C27D /* StatusBarView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 599EFBF724603EE00079C27D /* StatusBarView.xib */; };
599EFBFA246043B50079C27D /* StatusBarItemView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 599EFBF9246043B50079C27D /* StatusBarItemView.xib */; };
599EFBFC246045A90079C27D /* StatusBarItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 599EFBFB246045A90079C27D /* StatusBarItemView.swift */; };
5F260B1D24DDA3C800882975 /* NibView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F260B1C24DDA3C800882975 /* NibView.swift */; };
5F260B1F24DDA3F300882975 /* LoadableNib.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F260B1E24DDA3F300882975 /* LoadableNib.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -37,6 +39,8 @@
599EFBF724603EE00079C27D /* StatusBarView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = StatusBarView.xib; sourceTree = "<group>"; };
599EFBF9246043B50079C27D /* StatusBarItemView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = StatusBarItemView.xib; sourceTree = "<group>"; };
599EFBFB246045A90079C27D /* StatusBarItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusBarItemView.swift; sourceTree = "<group>"; };
5F260B1C24DDA3C800882975 /* NibView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NibView.swift; sourceTree = "<group>"; };
5F260B1E24DDA3F300882975 /* LoadableNib.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadableNib.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -106,6 +110,7 @@
599EFBF4246002CA0079C27D /* Core */ = {
isa = PBXGroup;
children = (
5F3CB8C224E1353900DC8CC9 /* Helper */,
599EFBF5246002E80079C27D /* StatusBarView.swift */,
599EFBFB246045A90079C27D /* StatusBarItemView.swift */,
599EFBF724603EE00079C27D /* StatusBarView.xib */,
Expand All @@ -114,6 +119,15 @@
path = Core;
sourceTree = "<group>";
};
5F3CB8C224E1353900DC8CC9 /* Helper */ = {
isa = PBXGroup;
children = (
5F260B1C24DDA3C800882975 /* NibView.swift */,
5F260B1E24DDA3F300882975 /* LoadableNib.swift */,
);
path = Helper;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -227,7 +241,9 @@
buildActionMask = 2147483647;
files = (
599EFBF6246002E80079C27D /* StatusBarView.swift in Sources */,
5F260B1F24DDA3F300882975 /* LoadableNib.swift in Sources */,
599EFBFC246045A90079C27D /* StatusBarItemView.swift in Sources */,
5F260B1D24DDA3C800882975 /* NibView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// LoadableNib.swift
// StatusBarView
//
// Created by Barış Uyar on 7.08.2020.
// Copyright © 2020 Ersen Tekin. All rights reserved.
//

import UIKit

public protocol LoadableNib: class {
static var name: String { get }
}

public extension LoadableNib where Self: UIView {
static var name: String {
return String(describing: Self.self)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// NibView.swift
// StatusBarView
//
// Created by Barış Uyar on 7.08.2020.
// Copyright © 2020 Ersen Tekin. All rights reserved.
//

import UIKit

public class NibView: UIView, LoadableNib {

public override init(frame: CGRect) {
super.init(frame: frame)
setup()
}

required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}

fileprivate func setup() {
guard let className = String(describing: self.classForCoder).components(separatedBy: ".").last else { return }
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: className, bundle: bundle)
guard let view = nib.instantiate(withOwner: self, options: nil).first as? UIView else { return }

view.backgroundColor = .clear
addSubview(view)
view.translatesAutoresizingMaskIntoConstraints = false

addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[childView]|",
options: [],
metrics: nil,
views: ["childView": view]))
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[childView]|",
options: [],
metrics: nil,
views: ["childView": view]))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,16 @@ extension StatusBarItemView {
}
}

public class StatusBarItemView: UIView {
private weak var containerView: UIView!
public class StatusBarItemView: NibView {
@IBOutlet private weak var outerCircleView: UIView!
@IBOutlet private weak var innerCircleView: UIView!
@IBOutlet private weak var shadowCircleView: UIView!
@IBOutlet private weak var titleLabel: UILabel!

override init(frame: CGRect) {
super.init(frame: frame)
setup()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}

func configure(title: String, color: UIColor, isActive: Bool) {
titleLabel.textColor = color
titleLabel.text = title
titleLabel.lineBreakMode = .byWordWrapping

if isActive {
innerCircleView.backgroundColor = color
Expand All @@ -61,32 +51,4 @@ public class StatusBarItemView: UIView {
shadowCircleView.backgroundColor = .clear
}
}

// MARK: - Private
private func setup() {
backgroundColor = UIColor.clear
let nibView = loadNib()
containerView = nibView
containerView.frame = bounds
addSubview(containerView)

containerView.translatesAutoresizingMaskIntoConstraints = false
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[childView]|",
options: [],
metrics: nil,
views: ["childView": nibView]))
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[childView]|",
options: [],
metrics: nil,
views: ["childView": nibView]))

titleLabel.lineBreakMode = .byWordWrapping
}

private func loadNib() -> UIView {
let bundle = Bundle(for: type(of: self))
let nibName = type(of: self).description().components(separatedBy: ".").last!
let nib = UINib(nibName: nibName, bundle: bundle)
return nib.instantiate(withOwner: self, options: nil).first as! UIView
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,11 @@ extension StatusBarView {
}
}

public class StatusBarView: UIView {
public class StatusBarView: NibView {
@IBOutlet private weak var statusesStackView: UIStackView!
@IBOutlet private weak var linesStackView: UIStackView!
@IBOutlet private weak var linesStackViewLeadingConstraint: NSLayoutConstraint!
@IBOutlet private weak var linesStackViewTrailingConstraint: NSLayoutConstraint!
private weak var containerView: UIView!

override init(frame: CGRect) {
super.init(frame: frame)
setup()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}

/**
Configures the view with the given parameters.
Expand All @@ -46,6 +35,7 @@ public class StatusBarView: UIView {
passiveColor: UIColor = .systemGray) {
removeAllSubviews(of: statusesStackView)
removeAllSubviews(of: linesStackView)
guard !titles.isEmpty else { return }

var isLastActiveItem = false
for (index, title) in titles.enumerated() {
Expand All @@ -64,7 +54,6 @@ public class StatusBarView: UIView {
isLastActiveItem = true
}
}
guard titles.count > 0 else { return }

let statusesWidth = bounds.width - (CGFloat(titles.count - 1) * statusesStackView.spacing)
let linesSpacing = (statusesWidth / CGFloat(titles.count)) / 2
Expand All @@ -73,30 +62,6 @@ public class StatusBarView: UIView {
}

// MARK: - Private
private func setup() {
backgroundColor = UIColor.clear
let nibView = loadNib()
containerView = nibView
containerView.frame = bounds
addSubview(containerView)

containerView.translatesAutoresizingMaskIntoConstraints = false
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[childView]|",
options: [],
metrics: nil,
views: ["childView": nibView]))
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[childView]|",
options: [],
metrics: nil,
views: ["childView": nibView]))
}

private func loadNib() -> UIView {
let bundle = Bundle(for: type(of: self))
let nibName = type(of: self).description().components(separatedBy: ".").last!
let nib = UINib(nibName: nibName, bundle: bundle)
return nib.instantiate(withOwner: self, options: nil).first as! UIView
}

private func removeAllSubviews(of stackView: UIStackView) {
for subview in stackView.arrangedSubviews {
Expand Down