Skip to content

Commit 1fc80ca

Browse files
committed
Add the ability to specify image tint color and text color for each SegmentioItem
1 parent 22a843b commit 1fc80ca

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

Segmentio/Source/Cells/SegmentioCell.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,16 @@ class SegmentioCell: UICollectionViewCell {
286286
if style.isWithImage() {
287287
segmentImageView?.contentMode = options.imageContentMode
288288
segmentImageView?.image = content.image
289+
if let imageTintColor = content.imageTintColor {
290+
segmentImageView?.tintColor = imageTintColor
291+
}
289292
}
290293

291294
if style.isWithText() {
292295
segmentTitleLabel?.textAlignment = options.labelTextAlignment
293296
segmentTitleLabel?.numberOfLines = options.labelTextNumberOfLines
294297
let defaultState = options.states.defaultState
295-
segmentTitleLabel?.textColor = defaultState.titleTextColor
298+
segmentTitleLabel?.textColor = content.textColor ?? defaultState.titleTextColor
296299
segmentTitleLabel?.font = defaultState.titleFont
297300
segmentTitleLabel?.text = content.title
298301
segmentTitleLabel?.minimumScaleFactor = 0.5

Segmentio/Source/SegmentioOptions.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import UIKit
1313
public struct SegmentioItem {
1414

1515
public var title: String?
16+
public var textColor: UIColor?
1617
public var image: UIImage?
1718
public var selectedImage: UIImage?
19+
public var imageTintColor: UIColor?
1820
public var badgeCount: Int?
1921
public var badgeColor: UIColor?
2022
public var intrinsicWidth: CGFloat {
@@ -24,10 +26,12 @@ public struct SegmentioItem {
2426
return label.intrinsicContentSize.width
2527
}
2628

27-
public init(title: String?, image: UIImage?, selectedImage: UIImage? = nil) {
29+
public init(title: String?, image: UIImage?, selectedImage: UIImage? = nil, titleColor: UIColor? = nil, imageTintColor: UIColor? = nil) {
2830
self.title = title
31+
self.textColor = titleColor
2932
self.image = image
3033
self.selectedImage = selectedImage ?? image
34+
self.imageTintColor = imageTintColor
3135
}
3236

3337
public mutating func addBadge(_ count: Int, color: UIColor) {

0 commit comments

Comments
 (0)