How can ı create a custom StackView programmatically

import Foundation
import UIKit

public struct Badge {
    let lineType: LineType
    let badgeType: BadgeType
    let withIcon: Bool
    let iconPosition: IconPosition
    let text: String
    let font: UIFont

    public init(
        lineType: LineType,
        badgeType: BadgeType,
        withIcon: Bool,
        iconPosition: IconPosition,
        text: String,
        font: UIFont
    ) {
        self.lineType = lineType
        self.badgeType = badgeType
        self.withIcon = withIcon
        self.iconPosition = iconPosition
        self.text = text
        self.font = font
    }
}

public final class CustomBadgeView: UIStackView {

    private var label: GTBadgeLabel?
    private var imageView: GTBadgeImageView?

    public convenience init(
        label: GTBadgeLabel?,
        imageView: GTBadgeImageView?
    ) {
        self.init()
        self.label = label
        self.imageView = imageView
        setCustomBadgeStackView(label: label, imageView: imageView)
    }

    private func setCustomBadgeStackView(label: GTBadgeLabel?, imageView: GTBadgeImageView?) {
        guard let label = label, let imageView = imageView else { return }
        axis  = .horizontal
        distribution  = .equalSpacing
        alignment = .center
        spacing   = 1.0
        backgroundColor = label.backgroundColor
        addArrangedSubview(imageView)
        addArrangedSubview(label)
        translatesAutoresizingMaskIntoConstraints = false
    }
}

public final class GTBadgeLabel: UILabel {

    private var badge: Badge?

    public convenience init(
        badge: Badge?
    ) {
        self.init()
        self.badge = badge
        setCustomBadgeLabel(badge: badge)
    }

    private func setCustomBadgeLabel(badge: Badge?) {
        guard let badge else { return }
        layer.masksToBounds = true
        layer.cornerRadius = 5
        backgroundColor = badge.badgeType.backgroundColor
        numberOfLines = badge.lineType.rawValue
        text = badge.text
        textColor = badge.badgeType.textColor
        textAlignment = .center
        backgroundColor = badge.badgeType.backgroundColor
    }
}

public final class GTBadgeImageView: UIImageView {

    private var icon: String?

    public convenience init(
        icon: String?
    ) {
        self.init()
        self.icon = icon

    }

    private func setCustomBadgeImageView(iconName: String?) {
        guard let iconName = iconName else { return }
        image = UIImage(named: iconName)
    }
}


public enum LineType: Int {
    case singleLine = 1
    case multipleLine = 0
}

public enum BadgeType {
    case danger
    case warning
    case neutral
    case counter
    case common

    var backgroundColor: UIColor {
        switch self {
        case .danger:
            return .systemPink
        case .warning:
            return  .yellow
        case .neutral:
            return  .gray
        case .counter:
            return  .blue
        case .common:
            return  .white
        }
    }
    var textColor: UIColor {
        switch self {
        case .danger:
            return .red
        case .warning:
            return   .black
        case .neutral:
            return  .black
        case .counter:
            return  .black
        case .common:
            return  .black
        }
    }
}

public enum IconPosition {
    case leftSide
    case rightSide
}
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let stackView = CustomBadgeView(
            label: GTBadgeLabel(
                badge: Badge(
                    lineType: .singleLine,
                    badgeType: .common,
                    withIcon: true,
                    iconPosition: .leftSide,
                    text: "Selam",
                    font: UIFont.systemFont(ofSize: 8)
                )
            ),
            imageView: GTBadgeImageView(icon: "applications")
        )
        self.view.addSubview(stackView)
        stackView.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: 50).isActive = true
        stackView.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: -50).isActive = true
        stackView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 100).isActive = true

        view.backgroundColor = .lightGray
    }
}

the first part is where I create my custom components and the second part is where I call components
but in the end I did not get the result I wanted.

I shared the after build. You can see the final version in the screenshot
insert image description here

I tried to add constrait programmatically but I could not find a solution.

The icon does not appear and the stackview view is very different, and the label in the stackview sticks to the stackview, I think it will be like that when the icon appears.

How can I show the icon and give space to the ones in the stackview

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật