rb2030 rb2030 - 6 months ago 36
Swift Question

Updating a label with an integer from external source

I am currently trying to build a label using the help of


This label should replicate the data given to it from an external source in the UI.

This is the code I currently have.

I would like to incorporate an
and change the
that is represented in the circle.

I am trying to create this in my own custom class. Please see my code thus far below.


import Foundation
import UIKit

class NumberInCircleView: UIView {

var numberLabel: UILabel!

override init(frame: CGRect) {
super.init(frame: frame)


required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)


func setupViews() {

self.numberLabel = UILabel(frame: .zero)
self.numberLabel.snp.makeConstraints { (make) in

self.layer.cornerRadius = 30
self.backgroundColor = UIColor.red
self.layer.borderWidth = 1
self.layer.borderColor = UIColor.black.cgColor
self.numberLabel.text = "1"
self.numberLabel.textAlignment = .center
self.numberLabel.textColor = UIColor.white
self.numberLabel.adjustsFontSizeToFitWidth = true
self.numberLabel.minimumScaleFactor = 0.5


Answer Source

You can set the integer by making it string.

var count:Int = 0
self.numberLabel.text = "\(count)"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download