Merge branch 'master' of github.com:NSMyself/Segmentio

This commit is contained in:
Ilya 2017-09-01 17:10:50 +03:00
commit 2ffa43f898
3 changed files with 14 additions and 4 deletions

View File

@ -130,7 +130,7 @@ class SegmentioCell: UICollectionViewCell {
configurateBadgeWithCount(content.badgeCount, color: content.badgeColor) configurateBadgeWithCount(content.badgeCount, color: content.badgeColor)
} }
func configure(selected: Bool) { func configure(selected: Bool, selectedImage:UIImage? = nil, image:UIImage? = nil) {
cellSelected = selected cellSelected = selected
let selectedState = options.states.selectedState let selectedState = options.states.selectedState
@ -140,6 +140,12 @@ class SegmentioCell: UICollectionViewCell {
segmentTitleLabel?.textColor = selected ? selectedState.titleTextColor : defaultState.titleTextColor segmentTitleLabel?.textColor = selected ? selectedState.titleTextColor : defaultState.titleTextColor
segmentTitleLabel?.font = selected ? selectedState.titleFont : defaultState.titleFont segmentTitleLabel?.font = selected ? selectedState.titleFont : defaultState.titleFont
} }
backgroundColor = selected ? selectedState.backgroundColor : defaultState.backgroundColor
if (style != .onlyLabel) {
segmentImageView?.image = selected ? selectedImage : image
}
} }
func configurateBadgeWithCount(_ badgeCount: Int?, color: UIColor?) { func configurateBadgeWithCount(_ badgeCount: Int?, color: UIColor?) {

View File

@ -537,14 +537,16 @@ extension Segmentio: UICollectionViewDataSource {
withReuseIdentifier: segmentioStyle.rawValue, withReuseIdentifier: segmentioStyle.rawValue,
for: indexPath) as! SegmentioCell for: indexPath) as! SegmentioCell
let content = segmentioItems[indexPath.row]
cell.configure( cell.configure(
content: segmentioItems[indexPath.row], content: content,
style: segmentioStyle, style: segmentioStyle,
options: segmentioOptions, options: segmentioOptions,
isLastCell: indexPath.row == segmentioItems.count - 1 isLastCell: indexPath.row == segmentioItems.count - 1
) )
cell.configure(selected: (indexPath.row == selectedSegmentioIndex)) cell.configure(selected: (indexPath.row == selectedSegmentioIndex), selectedImage:content.selectedImage, image:content.image)
return cell return cell
} }

View File

@ -14,12 +14,14 @@ public struct SegmentioItem {
public var title: String? public var title: String?
public var image: UIImage? public var image: UIImage?
public var selectedImage: UIImage?
public var badgeCount: Int? public var badgeCount: Int?
public var badgeColor: UIColor? public var badgeColor: UIColor?
public init(title: String?, image: UIImage?) { public init(title: String?, image: UIImage?, selectedImage: UIImage? = nil) {
self.title = title self.title = title
self.image = image self.image = image
self.selectedImage = selectedImage
} }
public mutating func addBadge(_ count: Int, color: UIColor) { public mutating func addBadge(_ count: Int, color: UIColor) {