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

Unfilled icon color #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 18 additions & 5 deletions AARatingBar/Classes/AARatingBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ import UIKit
}
}

/// AAARatingBar unfilled color
@IBInspectable open var unfilledColor: UIColor = .lightGray {
didSet {
setNeedsLayout()
}
}

/// AARatingBar Animaiton Bool
@IBInspectable open var canAnimate: Bool = true {
didSet{
Expand Down Expand Up @@ -139,11 +146,11 @@ import UIKit
/// Draw Initial rating bar
func drawRatingBar() {

let unFilledView = getRatingView(withIcon: unFilledIcon)
filledView = getRatingView(withIcon: filledIcon)
let unFilledView = getRatingView(withIcon: unFilledIcon, filled: false)
filledView = getRatingView(withIcon: filledIcon, filled: true)

addSubview(filledView)
addSubview(unFilledView)
addSubview(filledView)

}

Expand All @@ -160,7 +167,7 @@ import UIKit
///
/// - Parameter text: text icon for rating
/// - Returns: view that contained specific type of rating icons
func getRatingView(withIcon text: String) -> UIView {
func getRatingView(withIcon text: String, filled: Bool) -> UIView {
let view = UIView(frame: self.bounds)
view.clipsToBounds = true
view.backgroundColor = .clear
Expand All @@ -177,7 +184,13 @@ import UIKit
let starView = UILabel(frame: frame)
starView.text = text
starView.textColor = color
starView.font = starView.font.withSize(ratingWidth)
starView.textAlignment = .center

if !filled {
starView.textColor = unfilledColor
}

starView.font = starView.font.withSize(bounds.height)
starView.sizeThatFits(fitSize)
view.addSubview(starView)
}
Expand Down