Scaling Current Dot of Uipagecontrol and Keeping It Centered

Scaling current dot of UIPageControl and keeping it centered

I got it finally working by rewriting all the subviews constraints by myself.

// https://stackoverflow.com/a/55063316/1033581
class DefaultPageControl: UIPageControl {

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

override func sendAction(_ action: Selector, to target: Any?, for event: UIEvent?) {
super.sendAction(action, to: target, for: event)
updateDots()
}

private func updateDots() {
let currentDot = subviews[currentPage]
let largeScaling = CGAffineTransform(scaleX: 3.0, y: 3.0)
let smallScaling = CGAffineTransform(scaleX: 1.0, y: 1.0)

subviews.forEach {
// Apply the large scale of newly selected dot.
// Restore the small scale of previously selected dot.
$0.transform = $0 == currentDot ? largeScaling : smallScaling
}
}

override func updateConstraints() {
super.updateConstraints()
// We rewrite all the constraints
rewriteConstraints()
}

private func rewriteConstraints() {
let systemDotSize: CGFloat = 7.0
let systemDotDistance: CGFloat = 16.0

let halfCount = CGFloat(subviews.count) / 2
subviews.enumerated().forEach {
let dot = $0.element
dot.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.deactivate(dot.constraints)
NSLayoutConstraint.activate([
dot.widthAnchor.constraint(equalToConstant: systemDotSize),
dot.heightAnchor.constraint(equalToConstant: systemDotSize),
dot.centerYAnchor.constraint(equalTo: centerYAnchor, constant: 0),
dot.centerXAnchor.constraint(equalTo: centerXAnchor, constant: systemDotDistance * (CGFloat($0.offset) - halfCount))
])
}
}
}

System constants in the code (7.0 and 16.0) are respectively the size and the distance found for a default UIPageControl dot on iOS 12.

result

Swift PageControl larger dot on current page

UIPageControl is not that customizable. Use a library like this one

TAPageControl

Is works the same way as UIPageControl and you can easily customize current and non current page dots by setting the properties dotImage and currentDotImage.

UIPageControl Dot Size for current page

Swift

func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {

let x = targetContentOffset.pointee.x

pageControl.currentPage = Int(x / self.frame.width)


// on each dot, call the transform of scale 1 to restore the scale of previously selected dot

pageControl.subviews.forEach {
$0.transform = CGAffineTransform(scaleX: 1, y: 1)
}

// transform the scale of the current subview dot, adjust the scale as required, but bigger the scale value, the downward the dots goes from its centre.
// You can adjust the centre anchor of the selected dot to keep it in place approximately.

let centreBeforeScaling = self.pageControl.subviews[self.pageControl.currentPage].center

self.pageControl.subviews[self.pageControl.currentPage].transform = CGAffineTransform(scaleX: 1.5, y: 1.5)


// Reposition using autolayout

self.pageControl.subviews[self.pageControl.currentPage].translatesAutoresizingMaskIntoConstraints = false

self.pageControl.subviews[self.pageControl.currentPage].centerYAnchor.constraint(equalTo: self.pageControl.subviews[0].centerYAnchor , constant: 0)

self.pageControl.subviews[self.pageControl.currentPage].centerXAnchor.constraint(equalTo: self.pageControl.subviews[0].centerXAnchor , constant: 0)


// self.pageControl.subviews[self.pageControl.currentPage].layer.anchorPoint = centreBeforeScaling

}

WatchKit UIPageControl Dot Colour

As written by an Apple Engineer in the Dev Forums, it's not possible to customize the color of the page control at this time.

Source: https://devforums.apple.com/message/1100695#1100695

Find two consecutive rows

Assuming the rows have sequential IDs, something like this may be what you're looking for:

select top 1 * 
from
Bills b1
inner join Bills b2 on b1.id = b2.id - 1
where
b1.IsEstimate = 1 and b2.IsEstimate = 1
order by
b1.BillDate desc


Related Topics



Leave a reply



Submit