CountdownLabel icon indicating copy to clipboard operation
CountdownLabel copied to clipboard

Label text stroke

Open otymartin opened this issue 7 years ago • 4 comments

@suzuki-0000 I want to add a stroke to the timer with NSMutableAttributedString however it wont work

let attribs = [
            NSStrokeColorAttributeName: UIColor.blackColor(), NSForegroundColorAttributeName: UIColor.yellowColor(),
            NSStrokeWidthAttributeName: 2.0
        ]

        self.countdownLabel.attributedText = NSAttributedString(string: self.countdownLabel.text, attributes: attribs)

otymartin avatar Aug 22 '16 22:08 otymartin

hi. how about morphingEnabled = false in your countdownlabel?

suzuki-0000 avatar Aug 24 '16 09:08 suzuki-0000

@suzuki-0000 Didnt work. For some reason it would only work on the first countdown time then stop working the rest of the way. this is my embarassing solution

struct CountDownStroke {

    let textFontAttributes = [
        NSFontAttributeName : UIFont.time(),
        NSForegroundColorAttributeName: UIColor.whiteColor(),
        NSStrokeColorAttributeName: UIColor.blackColor().colorWithAlphaComponent(0.5),
        NSStrokeWidthAttributeName: -0.5
    ]

    let redFontAttributes = [
        NSFontAttributeName : UIFont.time(),
        NSForegroundColorAttributeName: UIColor.redColor().colorWithAlphaComponent(0.8),
        NSStrokeColorAttributeName: UIColor.blackColor().colorWithAlphaComponent(0.5),
        NSStrokeWidthAttributeName: -0.5
    ]

    func loadAttributes(countdownLabel: CountdownLabel) {

        countdownLabel.setCountDownTime(15)
        countdownLabel.timeFormat = "ss"

        dispatch(queue: .main) {
            countdownLabel.attributedText = NSAttributedString(string: countdownLabel.text, attributes: self.textFontAttributes)
        }

        countdownLabel.then(15) {
            dispatch(queue: .main) {
                countdownLabel.hidden = false
                countdownLabel.attributedText = NSAttributedString(string: countdownLabel.text, attributes: self.textFontAttributes)
            }
        }
        countdownLabel.then(14) {
            dispatch(queue: .main) {
                countdownLabel.attributedText = NSAttributedString(string: countdownLabel.text, attributes: self.textFontAttributes)
            }
        }
        countdownLabel.then(13) {
            dispatch(queue: .main) {
                countdownLabel.attributedText = NSAttributedString(string: countdownLabel.text, attributes: self.textFontAttributes)
            }
        }
        countdownLabel.then(12) {
            dispatch(queue: .main) {
                countdownLabel.attributedText = NSAttributedString(string: countdownLabel.text, attributes: self.textFontAttributes)
            }
        }
        countdownLabel.then(11) {
            dispatch(queue: .main) {
                countdownLabel.attributedText = NSAttributedString(string: countdownLabel.text, attributes: self.textFontAttributes)
            }
        }
        countdownLabel.then(10) {
            dispatch(queue: .main) {
                countdownLabel.timeFormat = "s"
                countdownLabel.attributedText = NSAttributedString(string: countdownLabel.text, attributes: self.textFontAttributes)
            }
        }
        countdownLabel.then(9) {
            dispatch(queue: .main) {
                countdownLabel.attributedText = NSAttributedString(string: countdownLabel.text, attributes: self.textFontAttributes)
            }
        }
        countdownLabel.then(8) {
            dispatch(queue: .main) {
                countdownLabel.attributedText = NSAttributedString(string: countdownLabel.text, attributes: self.textFontAttributes)
            }
        }
        countdownLabel.then(7) {
            dispatch(queue: .main) {
                countdownLabel.attributedText = NSAttributedString(string: countdownLabel.text, attributes: self.textFontAttributes)
            }
        }
        countdownLabel.then(6) {
            dispatch(queue: .main) {
                countdownLabel.textColor = UIColor.redColor()
                countdownLabel.attributedText = NSAttributedString(string: countdownLabel.text, attributes: self.textFontAttributes)
            }
        }
        countdownLabel.then(5) {
            dispatch(queue: .main) {
                countdownLabel.textColor = UIColor.redColor()
                countdownLabel.attributedText = NSAttributedString(string: countdownLabel.text, attributes: self.redFontAttributes)
            }
        }
        countdownLabel.then(4) {
            dispatch(queue: .main) {
                countdownLabel.attributedText = NSAttributedString(string: countdownLabel.text, attributes: self.redFontAttributes)
            }
        }
        countdownLabel.then(3) {
            dispatch(queue: .main) {
                countdownLabel.attributedText = NSAttributedString(string: countdownLabel.text, attributes: self.redFontAttributes)
            }
        }
        countdownLabel.then(2) {
            dispatch(queue: .main) {
                countdownLabel.attributedText = NSAttributedString(string: countdownLabel.text, attributes: self.redFontAttributes)
            }
        }
        countdownLabel.then(1) {
            dispatch(queue: .main) {
                countdownLabel.attributedText = NSAttributedString(string: countdownLabel.text, attributes: self.redFontAttributes)
            }
        }
    }
}

otymartin avatar Aug 24 '16 12:08 otymartin

you want to do something like this? I found a bug in CountdownAttributedText test

suzuki-0000 avatar Aug 25 '16 02:08 suzuki-0000

@suzuki-0000 Hi like this.

private var textAttributes: [String: NSObject] {
    let textAttributes = [
        NSForegroundColorAttributeName: UIColor.whiteColor(),
        NSStrokeColorAttributeName: UIColor.blackColor(),
        NSFontAttributeName: UIFont.navigation(),
        NSStrokeWidthAttributeName: -1.5
    ]
    return textAttributes
}

 self.countdownLabel.attributedText = NSAttributedString(string: self.countdownLabel.text, attributes: attributes)

//This currently does not work

otymartin avatar Sep 24 '16 02:09 otymartin