Scaling current dot of UIPageControl and keeping it centeredUIPageControl Dot Size for current pageSwift PageControl larger dot on current pageUIPageControl dot for a search pageHow can I change the color of pagination dots of UIPageControl?Dots of UIPageControlWatchKit UIPageControl Dot ColourHow to change the color of pagination dots in UIPageControl with a different color per pageControl “active” dot in UIPageControlAdd border for dots in UIPageControlCustom UIPageControl with dot imagesSwift UIPageControl not showing dotsUIPageControl Dot Size for current page
Time travel short story where a man arrives in the late 19th century in a time machine and then sends the machine back into the past
Is the destination of a commercial flight important for the pilot?
Products and sum of cubes in Fibonacci
Ways to speed up user implemented RK4
Is exact Kanji stroke length important?
Irreducibility of a simple polynomial
Is there any reason not to eat food that's been dropped on the surface of the moon?
Greatest common substring
Is HostGator storing my password in plaintext?
At which point does a character regain all their Hit Dice?
Implement the Thanos sorting algorithm
How does a character multiclassing into warlock get a focus?
How do I keep an essay about "feeling flat" from feeling flat?
Coordinate position not precise
Your magic is very sketchy
Everything Bob says is false. How does he get people to trust him?
Displaying the order of the columns of a table
How to be diplomatic in refusing to write code that breaches the privacy of our users
What are the ramifications of creating a homebrew world without an Astral Plane?
How was Earth single-handedly capable of creating 3 of the 4 gods of chaos?
Applicability of Single Responsibility Principle
How can I replace every global instance of "x[2]" with "x_2"
How do I define a right arrow with bar in LaTeX?
Tiptoe or tiphoof? Adjusting words to better fit fantasy races
Scaling current dot of UIPageControl and keeping it centered
UIPageControl Dot Size for current pageSwift PageControl larger dot on current pageUIPageControl dot for a search pageHow can I change the color of pagination dots of UIPageControl?Dots of UIPageControlWatchKit UIPageControl Dot ColourHow to change the color of pagination dots in UIPageControl with a different color per pageControl “active” dot in UIPageControlAdd border for dots in UIPageControlCustom UIPageControl with dot imagesSwift UIPageControl not showing dotsUIPageControl Dot Size for current page
I've subclassed UIPageControl in order to have its current dot bigger.
class CustomPageControl: UIPageControl
override var currentPage: Int
didSet
updateDots()
func updateDots()
let currentDot = subviews[currentPage]
let largeScaling = CGAffineTransform(scaleX: 3, y: 3)
subviews.forEach
// apply the large scale of newly selected dot
// restore the normal scale of previously selected dot
$0.transform = $0 == currentDot ? largeScaling : .identity
But the result of the transform isn't centered (the red dot should be aligned with the others):
I've tried (on iOS 12):
- changing the
frame
orcenter
ofcurrentDot
has no effect. - changing the transform to include a
translatedBy(x: CGFloat, y: CGFloat)
has no effect. changing the constraints like here is making the first dot jumping:
currentDot.translatesAutoresizingMaskIntoConstraints = false
currentDot.centerYAnchor.constraint(equalTo: self.centerYAnchor, constant: 0)
currentDot.centerXAnchor.constraint(equalTo: self.centerXAnchor, constant: 0)
ios swift uikit uipagecontrol
add a comment |
I've subclassed UIPageControl in order to have its current dot bigger.
class CustomPageControl: UIPageControl
override var currentPage: Int
didSet
updateDots()
func updateDots()
let currentDot = subviews[currentPage]
let largeScaling = CGAffineTransform(scaleX: 3, y: 3)
subviews.forEach
// apply the large scale of newly selected dot
// restore the normal scale of previously selected dot
$0.transform = $0 == currentDot ? largeScaling : .identity
But the result of the transform isn't centered (the red dot should be aligned with the others):
I've tried (on iOS 12):
- changing the
frame
orcenter
ofcurrentDot
has no effect. - changing the transform to include a
translatedBy(x: CGFloat, y: CGFloat)
has no effect. changing the constraints like here is making the first dot jumping:
currentDot.translatesAutoresizingMaskIntoConstraints = false
currentDot.centerYAnchor.constraint(equalTo: self.centerYAnchor, constant: 0)
currentDot.centerXAnchor.constraint(equalTo: self.centerXAnchor, constant: 0)
ios swift uikit uipagecontrol
Dot size is large then spec between two dots, try with small red dot.
– AtulParmar
Mar 8 at 9:57
@AtulParmar the positioning problem happens of course with any scale, large or small.
– Cœur
Mar 8 at 10:16
add a comment |
I've subclassed UIPageControl in order to have its current dot bigger.
class CustomPageControl: UIPageControl
override var currentPage: Int
didSet
updateDots()
func updateDots()
let currentDot = subviews[currentPage]
let largeScaling = CGAffineTransform(scaleX: 3, y: 3)
subviews.forEach
// apply the large scale of newly selected dot
// restore the normal scale of previously selected dot
$0.transform = $0 == currentDot ? largeScaling : .identity
But the result of the transform isn't centered (the red dot should be aligned with the others):
I've tried (on iOS 12):
- changing the
frame
orcenter
ofcurrentDot
has no effect. - changing the transform to include a
translatedBy(x: CGFloat, y: CGFloat)
has no effect. changing the constraints like here is making the first dot jumping:
currentDot.translatesAutoresizingMaskIntoConstraints = false
currentDot.centerYAnchor.constraint(equalTo: self.centerYAnchor, constant: 0)
currentDot.centerXAnchor.constraint(equalTo: self.centerXAnchor, constant: 0)
ios swift uikit uipagecontrol
I've subclassed UIPageControl in order to have its current dot bigger.
class CustomPageControl: UIPageControl
override var currentPage: Int
didSet
updateDots()
func updateDots()
let currentDot = subviews[currentPage]
let largeScaling = CGAffineTransform(scaleX: 3, y: 3)
subviews.forEach
// apply the large scale of newly selected dot
// restore the normal scale of previously selected dot
$0.transform = $0 == currentDot ? largeScaling : .identity
But the result of the transform isn't centered (the red dot should be aligned with the others):
I've tried (on iOS 12):
- changing the
frame
orcenter
ofcurrentDot
has no effect. - changing the transform to include a
translatedBy(x: CGFloat, y: CGFloat)
has no effect. changing the constraints like here is making the first dot jumping:
currentDot.translatesAutoresizingMaskIntoConstraints = false
currentDot.centerYAnchor.constraint(equalTo: self.centerYAnchor, constant: 0)
currentDot.centerXAnchor.constraint(equalTo: self.centerXAnchor, constant: 0)
ios swift uikit uipagecontrol
ios swift uikit uipagecontrol
edited Mar 11 at 4:29
Cœur
asked Mar 8 at 9:39
CœurCœur
19.1k9114155
19.1k9114155
Dot size is large then spec between two dots, try with small red dot.
– AtulParmar
Mar 8 at 9:57
@AtulParmar the positioning problem happens of course with any scale, large or small.
– Cœur
Mar 8 at 10:16
add a comment |
Dot size is large then spec between two dots, try with small red dot.
– AtulParmar
Mar 8 at 9:57
@AtulParmar the positioning problem happens of course with any scale, large or small.
– Cœur
Mar 8 at 10:16
Dot size is large then spec between two dots, try with small red dot.
– AtulParmar
Mar 8 at 9:57
Dot size is large then spec between two dots, try with small red dot.
– AtulParmar
Mar 8 at 9:57
@AtulParmar the positioning problem happens of course with any scale, large or small.
– Cœur
Mar 8 at 10:16
@AtulParmar the positioning problem happens of course with any scale, large or small.
– Cœur
Mar 8 at 10:16
add a comment |
1 Answer
1
active
oldest
votes
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()
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.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060432%2fscaling-current-dot-of-uipagecontrol-and-keeping-it-centered%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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()
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.
add a comment |
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()
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.
add a comment |
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()
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.
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()
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.
edited Mar 12 at 11:38
answered Mar 8 at 12:31
CœurCœur
19.1k9114155
19.1k9114155
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060432%2fscaling-current-dot-of-uipagecontrol-and-keeping-it-centered%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Dot size is large then spec between two dots, try with small red dot.
– AtulParmar
Mar 8 at 9:57
@AtulParmar the positioning problem happens of course with any scale, large or small.
– Cœur
Mar 8 at 10:16