alexhillc / AXPhotoViewer

An iOS/tvOS photo gallery viewer, useful for viewing a large (or small!) number of photos.
https://www.cocoacontrols.com/controls/axphotoviewer
MIT License
646 stars 119 forks source link

attributedDescription and attributedCredit apply #30

Closed deepmode closed 5 years ago

deepmode commented 6 years ago

Hi Alex,

I am trying to apply my custom attributes to "attributedDescription" and "attributedCredit" for the Photo object and apparently, I can only see the color attribute working but not for the font style and the paragraphStyle. Do I miss anything in the setup?

    var photos:[PhotoProtocol] = []
    for (index, eachLink) in self.photosLink.enumerated() {
        let p = Photo()
        p.url = URL(string: eachLink)

        if let cell = self.collectionView.cellForItem(at: indexPath) as? HHCVCell, index == indexPath.row {
            let image = cell.imageview.image
            p.image = image
        }

        let descriptionText = "Description goes here. \(index)" 
        let creditText =  "Image Credit \(index)"

        let desciptionAttributes = [NSAttributedStringKey.foregroundColor: HBConstants.Style.galleryCaptionColor, NSAttributedStringKey.font: HBConstants.Style.galleryCaptionFont]
        let description = NSAttributedString(string: descriptionText, attributes: desciptionAttributes)

        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.alignment = .right

        let creditAttributes = [NSAttributedStringKey.foregroundColor: HBConstants.Style.galleryCreditColor, NSAttributedStringKey.font: HBConstants.Style.galleryCreditFont, NSAttributedStringKey.paragraphStyle: paragraphStyle]
        let credit = NSAttributedString(string: creditText, attributes: creditAttributes)

        p.attributedDescription = description
        p.attributedCredit = credit
        photos.append(p)
    }

    let dataSource = PhotosDataSource(photos: photos, initialPhotoIndex: indexPath.row, prefetchBehavior: .aggressive)
banane commented 6 years ago

Yeah - I'm updating the caption font and also it's not affecting the size.