Skip to content

Instantly share code, notes, and snippets.

//Encontrar o menor e o maior valor em values
guard let maxValue = values.max() else { return }
guard let minValue = values.min() else { return }
values.forEach { (value) in
// Agora sabemos que o gráfico tem dois comportamentos para se normalizar, um deles se o menor valor for 0 e outro se o menor valor for diferente de 0. A lógica é a mesma em ambos, a diferença agora é a variação dos valores.
if minValue == 0 {
normalizedValue = 1-((maxValue-value)/(maxValue-minValue))
//Adicionando a legenda
let caption = UILabel()
caption.text = String(Double(value))
caption.adjustsFontSizeToFitWidth = true
caption.frame = CGRect(x: posX, y: posY-captionHeight, width: barWidth, height: captionHeight)
addSubview(caption)
//Encontrar o menor e o maior valor em values
guard let maxValue = values.max() else { return }
guard let minValue = values.min() else { return }
values.forEach { (value) in
//Normalizando os dados
let normalizedValue = 1-((maxValue-value)/(maxValue-minValue))
//Lembrando que posY agora é metade da altura da view - a altura da barra
var posX: CGFloat = 0.0
var barWidth: CGFloat = 30.0
values.forEach { (value) in
let posY = bounds.height/2 - value
let bar = CGRect(x: posX, y: posY, width: barWidth, height: value)
context.addRect(bar)
var values = [CGFloat]()
for i in 0...10 {
values.append(CGFloat(i))
}
let bar = CGRect(x: bounds.width/2, y: bounds.height/2, width: 100.0, height: 100.0)
context.addRect(bar)
context.setFillColor(UIColor.red.cgColor)
context.fillPath()
guard let context = UIGraphicsGetCurrentContext() else { return }
email me at eloisamariafalcao@gmail.com
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TableViewCell
cell.imagemCelula.image = UIImage(named: foto[indexPath.row])
cell.nomeCelula.text = seteMaravilhas[indexPath.row]
cell.paisCelula.text = paises[indexPath.row]
cell.view.backgroundColor = #colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 0.6)
return cell
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return seteMaravilhas.count
}