Как изменить размер и расстояние между точками на странице в Swift? - PullRequest
0 голосов
/ 18 марта 2020

enter image description here

Я хочу настроить управление страницей, как изображение.
Я уже искал это, но есть только масштаб сделки.
Я хочу изменить ширина, высота, расстояние.
Как я могу это сделать?

Я пробовал это

class DefaultPageControl: UIPageControl {

    override var currentPage: Int {
        didSet {
            updateDots()
        }
    }

    func updateDots() {
        let currentDot = subviews[currentPage]

        subviews.forEach {
            $0.frame.size = ($0 == currentDot) ? CGSize(width: 16, height: 4) : CGSize(width: 8, height: 4)
            $0.layer.cornerRadius = 2
        }
    }
}

Но как изменить расстояние ??

1 Ответ

0 голосов
/ 18 марта 2020

@ oddK Можете ли вы попробовать с этим ответом ниже. Это мое предположение.

    class DefaultPageControl: UIPageControl {

    override var currentPage: Int {
        didSet {
            updateDots()
        }
    }

    func updateDots() {
        let currentDot = subviews[currentPage]

        let spacing = 5.0

        subviews.forEach {
            $0.frame = ($0 == currentDot) ? CGRect(x: 0, y: 0, width: 16, height: 4) : CGRect(x: spacing, y: 0, width: 8, height: 4)
            //$0.frame.size = ($0 == currentDot) ? CGSize(width: 16, height: 4) : CGSize(width: 8, height: 4)
            $0.layer.cornerRadius = 2
        }
    }
}
...