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













1















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):
enter image description here



I've tried (on iOS 12):



  • changing the frame or center of currentDot 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)


    enter image description here











share|improve this question
























  • 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















1















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):
enter image description here



I've tried (on iOS 12):



  • changing the frame or center of currentDot 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)


    enter image description here











share|improve this question
























  • 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













1












1








1








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):
enter image description here



I've tried (on iOS 12):



  • changing the frame or center of currentDot 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)


    enter image description here











share|improve this question
















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):
enter image description here



I've tried (on iOS 12):



  • changing the frame or center of currentDot 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)


    enter image description here








ios swift uikit uipagecontrol






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












1 Answer
1






active

oldest

votes


















0














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.



result






share|improve this answer
























    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    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.



    result






    share|improve this answer





























      0














      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.



      result






      share|improve this answer



























        0












        0








        0







        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.



        result






        share|improve this answer















        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.



        result







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 12 at 11:38

























        answered Mar 8 at 12:31









        CœurCœur

        19.1k9114155




        19.1k9114155





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived