How to change font color in PDFKit

How do I change the font color in this scenario? Thanks!

//DATE TAKEN
    func addDateTaken(pageRect: CGRect, dateTakenTop: CGFloat) -> CGFloat {
        //1
        let dateTakenFont = UIFont.systemFont(ofSize: 12.0, weight: .semibold)
        //2
        let dateTakenAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: dateTakenFont]
        //3
        let attributedDateTaken = NSAttributedString(
            string: "Date Taken: \(dateTaken)",
            attributes: dateTakenAttributes
        )
        //4
        let dateTakenStringSize = attributedDateTaken.size()
        let x = (pageRect.width - dateTakenStringSize.width)
        let xx = (x - x) + 20
        //5
        let dateTakenStringRect = CGRect(
            x: xx,
            y: dateTakenTop,
            width: dateTakenStringSize.width,
            height: dateTakenStringSize.height
        )
        //6
        attributedDateTaken.draw(in: dateTakenStringRect)
        //7
        return dateTakenStringRect.origin.y + dateTakenStringRect.size.height
    }

Better asked over at Apple developer forums, StackoverFlow, other Apple developer sites. The question is about Apple frameworks, not Swift itself.

1 Like

You could also lookup NSAttributedString in the Apple SDK references available through Xcode.

1 Like

Look up NSAttributedString.Key.foregroundColor.

1 Like

Thanks dude!!! It worked.

Terms of Service

Privacy Policy

Cookie Policy