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

labelGenerator creating Multiple labels for each Part #65

Open
ChanakyaHirpara opened this issue May 4, 2021 · 0 comments
Open

labelGenerator creating Multiple labels for each Part #65

ChanakyaHirpara opened this issue May 4, 2021 · 0 comments

Comments

@ChanakyaHirpara
Copy link

ChanakyaHirpara commented May 4, 2021

var colors:[UIColor] = [ UIColor(hexString: "#F69300"), UIColor(hexString: "#93D460"), UIColor(hexString: "#5D86EF"), UIColor(hexString: "#F16051"), UIColor(hexString: "#FFFFFF")]
var texts:[String] = [ "Lorem", "Ipsum", "Correct", "Wrong", "Correct"]
var percentages:[CGFloat] = [15,12,18,25,30]
var textLayers:[PieLineTextLayer] = []
var sliceModels:[PieSliceModel] = []

for index in stride(from: 0, to: texts.count, by: 1) {
        
        sliceModels.append(PieSliceModel(value: Double(percentages[index]), color: colors[index]))
        
        let textLayerSettings = PieLineTextLayerSettings()
        textLayerSettings.label.font = Fonts.bold(size: 17)
        textLayerSettings.label.textColor = UIColor(hexString: "#F69300")

        let formatter = NumberFormatter()
        formatter.maximumFractionDigits = 1
        
        let textToSet = "\(percentages[index])% \(texts[index])"
        
        textLayerSettings.label.labelGenerator = { slice in
            
            let lbl = UILabel(frame: CGRect.zero)
            lbl.sizeToFit()
            lbl.text = textToSet
            lbl.textColor = self.colors[index]
            lbl.font = Fonts.bold(size: 18)
            
            lbl.setfont(text: textToSet, words: [self.texts[index]], firstFont: Fonts.bold(size: 18), secondFont: Fonts.medium(size: 14), wordColor: UIColor.white)
            return lbl
        }
        
        textLayerSettings.label.textGenerator = {slice in
            return textToSet
        }

        let textLayer = PieLineTextLayer()
        textLayer.settings = textLayerSettings
        
        textLayers.append(textLayer)
        
    }
    
    pieChart.models = sliceModels
    
    pieChart.layers = textLayers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant