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] - ImageOrLabel Style Added #138

Open
wants to merge 1 commit 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
4 changes: 4 additions & 0 deletions Segmentio.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
324B605E1D33E5200050B083 /* UIView+Appearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 324B60541D33E5200050B083 /* UIView+Appearance.swift */; };
324B605F1D33E5200050B083 /* Segmentio.swift in Sources */ = {isa = PBXBuildFile; fileRef = 324B60551D33E5200050B083 /* Segmentio.swift */; };
324B60601D33E5200050B083 /* SegmentioOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 324B60561D33E5200050B083 /* SegmentioOptions.swift */; };
B6D194A6234F1D2600314C03 /* SegmentioCellWithImageOrLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6D194A5234F1D2600314C03 /* SegmentioCellWithImageOrLabel.swift */; };
C5514DD81DAB5B82008F14AA /* BadgeViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5514DD31DAB5B82008F14AA /* BadgeViewPresenter.swift */; };
C5514DD91DAB5B82008F14AA /* BadgeWithCounterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5514DD51DAB5B82008F14AA /* BadgeWithCounterView.swift */; };
C5514DDA1DAB5B82008F14AA /* BadgeWithCounterViewBigSized.xib in Resources */ = {isa = PBXBuildFile; fileRef = C5514DD61DAB5B82008F14AA /* BadgeWithCounterViewBigSized.xib */; };
Expand All @@ -38,6 +39,7 @@
324B60541D33E5200050B083 /* UIView+Appearance.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Appearance.swift"; sourceTree = "<group>"; };
324B60551D33E5200050B083 /* Segmentio.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Segmentio.swift; sourceTree = "<group>"; };
324B60561D33E5200050B083 /* SegmentioOptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SegmentioOptions.swift; sourceTree = "<group>"; };
B6D194A5234F1D2600314C03 /* SegmentioCellWithImageOrLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentioCellWithImageOrLabel.swift; sourceTree = "<group>"; };
C5514DD31DAB5B82008F14AA /* BadgeViewPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BadgeViewPresenter.swift; sourceTree = "<group>"; };
C5514DD51DAB5B82008F14AA /* BadgeWithCounterView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BadgeWithCounterView.swift; sourceTree = "<group>"; };
C5514DD61DAB5B82008F14AA /* BadgeWithCounterViewBigSized.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BadgeWithCounterViewBigSized.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -103,6 +105,7 @@
324B60501D33E5200050B083 /* SegmentioCellWithImageOverLabel.swift */,
324B60511D33E5200050B083 /* SegmentioCellWithImageUnderLabel.swift */,
324B60521D33E5200050B083 /* SegmentioCellWithLabel.swift */,
B6D194A5234F1D2600314C03 /* SegmentioCellWithImageOrLabel.swift */,
);
path = Cells;
sourceTree = "<group>";
Expand Down Expand Up @@ -227,6 +230,7 @@
324B605F1D33E5200050B083 /* Segmentio.swift in Sources */,
324B60581D33E5200050B083 /* SegmentioCellWithImage.swift in Sources */,
324B605A1D33E5200050B083 /* SegmentioCellWithImageBeforeLabel.swift in Sources */,
B6D194A6234F1D2600314C03 /* SegmentioCellWithImageOrLabel.swift in Sources */,
324B605C1D33E5200050B083 /* SegmentioCellWithImageUnderLabel.swift in Sources */,
324B605E1D33E5200050B083 /* UIView+Appearance.swift in Sources */,
324B605D1D33E5200050B083 /* SegmentioCellWithLabel.swift in Sources */,
Expand Down
83 changes: 83 additions & 0 deletions Segmentio/Source/Cells/SegmentioCellWithImageOrLabel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// SegmentioCellWithImageOrLabel.swift
// Segmentio
//
// Created by Ahsan Ali on 10/10/2019.
//

import UIKit

class SegmentioCellWithImageOrLabel: SegmentioCell {

override func setupConstraintsForSubviews() {
super.setupConstraintsForSubviews()
guard let imageContainerView = imageContainerView else {
return
}
guard let containerView = containerView else {
return
}

let views = [
"imageContainerView": imageContainerView,
"containerView": containerView,
"contentView": contentView
]

// main constraints
let segmentImageViewHorizontConstraint = NSLayoutConstraint.constraints(
withVisualFormat: "V:[contentView]-(<=1)-[imageContainerView]",
options: [.alignAllCenterX],
metrics: nil,
views: views)
NSLayoutConstraint.activate(segmentImageViewHorizontConstraint)

let segmentImageViewVerticleConstraint = NSLayoutConstraint.constraints(
withVisualFormat: "H:[contentView]-(<=1)-[imageContainerView]",
options: [.alignAllCenterY],
metrics: nil,
views: views)
NSLayoutConstraint.activate(segmentImageViewVerticleConstraint)


let segmentTitleLabelHorizontConstraint = NSLayoutConstraint.constraints(
withVisualFormat: "V:[contentView]-(<=1)-[containerView]",
options: [.alignAllCenterX],
metrics: nil,
views: views
)
NSLayoutConstraint.activate(segmentTitleLabelHorizontConstraint)

let segmentTitleLabelVerticleConstraint = NSLayoutConstraint.constraints(
withVisualFormat: "H:[contentView]-(<=1)-[containerView]",
options: [.alignAllCenterY],
metrics: nil,
views: views
)
NSLayoutConstraint.activate(segmentTitleLabelVerticleConstraint)

// custom constraints
topConstraint = NSLayoutConstraint(
item: containerView,
attribute: .top,
relatedBy: .equal,
toItem: contentView,
attribute: .top,
multiplier: 1,
constant: padding
)
topConstraint?.isActive = true

bottomConstraint = NSLayoutConstraint(
item: contentView,
attribute: .bottom,
relatedBy: .equal,
toItem: imageContainerView,
attribute: .bottom,
multiplier: 1,
constant: padding
)
bottomConstraint?.isActive = true
}

}
2 changes: 2 additions & 0 deletions Segmentio/Source/Segmentio.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ open class Segmentio: UIView {
return SegmentioCellWithImageBeforeLabel.self
case .imageAfterLabel:
return SegmentioCellWithImageAfterLabel.self
case .imageOrLabel:
return SegmentioCellWithImageOrLabel.self
}
}

Expand Down
11 changes: 6 additions & 5 deletions Segmentio/Source/SegmentioOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,21 @@ public enum SegmentioPosition {

public enum SegmentioStyle: String {

case onlyLabel, onlyImage, imageOverLabel, imageUnderLabel, imageBeforeLabel, imageAfterLabel
case onlyLabel, onlyImage, imageOverLabel, imageUnderLabel, imageBeforeLabel, imageAfterLabel, imageOrLabel

public static let allStyles = [
onlyLabel,
onlyImage,
imageOverLabel,
imageUnderLabel,
imageBeforeLabel,
imageAfterLabel
imageAfterLabel,
imageOrLabel
]

public func isWithText() -> Bool {
switch self {
case .onlyLabel, .imageOverLabel, .imageUnderLabel, .imageBeforeLabel, .imageAfterLabel:
case .onlyLabel, .imageOverLabel, .imageUnderLabel, .imageBeforeLabel, .imageAfterLabel,.imageOrLabel:
return true
default:
return false
Expand All @@ -163,7 +164,7 @@ public enum SegmentioStyle: String {

public func isWithImage() -> Bool {
switch self {
case .imageOverLabel, .imageUnderLabel, .imageBeforeLabel, .imageAfterLabel, .onlyImage:
case .imageOverLabel, .imageUnderLabel, .imageBeforeLabel, .imageAfterLabel, .onlyImage,.imageOrLabel:
return true
default:
return false
Expand All @@ -173,7 +174,7 @@ public enum SegmentioStyle: String {
public var layoutMargins: CGFloat {
let defaultLayoutMargins: CGFloat = 8.0
switch self {
case .onlyLabel, .imageAfterLabel, .imageBeforeLabel, .imageOverLabel, .imageUnderLabel:
case .onlyLabel, .imageAfterLabel, .imageBeforeLabel, .imageOverLabel, .imageUnderLabel,.imageOrLabel:
return 4 * defaultLayoutMargins
case .onlyImage:
return 2 * defaultLayoutMargins
Expand Down