Increase area of UIButton in UIStackView












0















I have couple of UIButtons embedded in UIStackView. I understand UIStackView takes only the intrinsic size of UIButton when laying it out. But I want to increase height/width of UIButton when inside UIStackView. Without UIStackView, I can easily increase or decrease UIButtons frame size. What is the deal with UIStackView?



Detail: Let's say I gave 3 UIButtons with only UIImages and no text. Button 1 is 80x80, button 2 image is 30x30, button 3 image is 30x30. I would like touch area of button 2 and 3 to be atleast 45x45 without stretching the image. I can simply resize UIButton like this when it's not in UIStackView. But with UIStackView, all button sizes are the size of images (intrinsic size) which i don't know how to fix.










share|improve this question

























  • Can you share how would you like the way to show the buttons and what you currently have reached?

    – DionizB
    Nov 21 '18 at 16:21






  • 1





    You should be able to add height and/or width constraints to the buttons that you place in a stack view.

    – Duncan C
    Nov 21 '18 at 16:24











  • But using autolayout to set width and height of button, why am I getting autolayout errors (red boxes in storyboard), spacing value needs to be updated?

    – Deepak Sharma
    Nov 21 '18 at 16:31
















0















I have couple of UIButtons embedded in UIStackView. I understand UIStackView takes only the intrinsic size of UIButton when laying it out. But I want to increase height/width of UIButton when inside UIStackView. Without UIStackView, I can easily increase or decrease UIButtons frame size. What is the deal with UIStackView?



Detail: Let's say I gave 3 UIButtons with only UIImages and no text. Button 1 is 80x80, button 2 image is 30x30, button 3 image is 30x30. I would like touch area of button 2 and 3 to be atleast 45x45 without stretching the image. I can simply resize UIButton like this when it's not in UIStackView. But with UIStackView, all button sizes are the size of images (intrinsic size) which i don't know how to fix.










share|improve this question

























  • Can you share how would you like the way to show the buttons and what you currently have reached?

    – DionizB
    Nov 21 '18 at 16:21






  • 1





    You should be able to add height and/or width constraints to the buttons that you place in a stack view.

    – Duncan C
    Nov 21 '18 at 16:24











  • But using autolayout to set width and height of button, why am I getting autolayout errors (red boxes in storyboard), spacing value needs to be updated?

    – Deepak Sharma
    Nov 21 '18 at 16:31














0












0








0








I have couple of UIButtons embedded in UIStackView. I understand UIStackView takes only the intrinsic size of UIButton when laying it out. But I want to increase height/width of UIButton when inside UIStackView. Without UIStackView, I can easily increase or decrease UIButtons frame size. What is the deal with UIStackView?



Detail: Let's say I gave 3 UIButtons with only UIImages and no text. Button 1 is 80x80, button 2 image is 30x30, button 3 image is 30x30. I would like touch area of button 2 and 3 to be atleast 45x45 without stretching the image. I can simply resize UIButton like this when it's not in UIStackView. But with UIStackView, all button sizes are the size of images (intrinsic size) which i don't know how to fix.










share|improve this question
















I have couple of UIButtons embedded in UIStackView. I understand UIStackView takes only the intrinsic size of UIButton when laying it out. But I want to increase height/width of UIButton when inside UIStackView. Without UIStackView, I can easily increase or decrease UIButtons frame size. What is the deal with UIStackView?



Detail: Let's say I gave 3 UIButtons with only UIImages and no text. Button 1 is 80x80, button 2 image is 30x30, button 3 image is 30x30. I would like touch area of button 2 and 3 to be atleast 45x45 without stretching the image. I can simply resize UIButton like this when it's not in UIStackView. But with UIStackView, all button sizes are the size of images (intrinsic size) which i don't know how to fix.







ios swift uiview ios-autolayout uistackview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 16:26







Deepak Sharma

















asked Nov 21 '18 at 16:11









Deepak SharmaDeepak Sharma

1,3591837




1,3591837













  • Can you share how would you like the way to show the buttons and what you currently have reached?

    – DionizB
    Nov 21 '18 at 16:21






  • 1





    You should be able to add height and/or width constraints to the buttons that you place in a stack view.

    – Duncan C
    Nov 21 '18 at 16:24











  • But using autolayout to set width and height of button, why am I getting autolayout errors (red boxes in storyboard), spacing value needs to be updated?

    – Deepak Sharma
    Nov 21 '18 at 16:31



















  • Can you share how would you like the way to show the buttons and what you currently have reached?

    – DionizB
    Nov 21 '18 at 16:21






  • 1





    You should be able to add height and/or width constraints to the buttons that you place in a stack view.

    – Duncan C
    Nov 21 '18 at 16:24











  • But using autolayout to set width and height of button, why am I getting autolayout errors (red boxes in storyboard), spacing value needs to be updated?

    – Deepak Sharma
    Nov 21 '18 at 16:31

















Can you share how would you like the way to show the buttons and what you currently have reached?

– DionizB
Nov 21 '18 at 16:21





Can you share how would you like the way to show the buttons and what you currently have reached?

– DionizB
Nov 21 '18 at 16:21




1




1





You should be able to add height and/or width constraints to the buttons that you place in a stack view.

– Duncan C
Nov 21 '18 at 16:24





You should be able to add height and/or width constraints to the buttons that you place in a stack view.

– Duncan C
Nov 21 '18 at 16:24













But using autolayout to set width and height of button, why am I getting autolayout errors (red boxes in storyboard), spacing value needs to be updated?

– Deepak Sharma
Nov 21 '18 at 16:31





But using autolayout to set width and height of button, why am I getting autolayout errors (red boxes in storyboard), spacing value needs to be updated?

– Deepak Sharma
Nov 21 '18 at 16:31












2 Answers
2






active

oldest

votes


















2














If you add the width/height constraints to the buttons stack view will size it subviews based on the constraints and not the intrinsic size of buttons.






share|improve this answer
























  • I get autolayout errors (red boxes in storyboard) when manually specifying width and height of UIButton. Why should that occur?

    – Deepak Sharma
    Nov 21 '18 at 16:34













  • Because UIStackView tries to add own constraints according to its distribution and alignment.

    – olejnjak
    Nov 21 '18 at 16:52











  • What errors are you getting?

    – lorenzoliveto
    Nov 22 '18 at 10:07



















1














For this purpose I usually use the contentEdgeInsets property. If it is not sufficient, you would need to add some autolayout constraints.






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%2f53416177%2fincrease-area-of-uibutton-in-uistackview%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    If you add the width/height constraints to the buttons stack view will size it subviews based on the constraints and not the intrinsic size of buttons.






    share|improve this answer
























    • I get autolayout errors (red boxes in storyboard) when manually specifying width and height of UIButton. Why should that occur?

      – Deepak Sharma
      Nov 21 '18 at 16:34













    • Because UIStackView tries to add own constraints according to its distribution and alignment.

      – olejnjak
      Nov 21 '18 at 16:52











    • What errors are you getting?

      – lorenzoliveto
      Nov 22 '18 at 10:07
















    2














    If you add the width/height constraints to the buttons stack view will size it subviews based on the constraints and not the intrinsic size of buttons.






    share|improve this answer
























    • I get autolayout errors (red boxes in storyboard) when manually specifying width and height of UIButton. Why should that occur?

      – Deepak Sharma
      Nov 21 '18 at 16:34













    • Because UIStackView tries to add own constraints according to its distribution and alignment.

      – olejnjak
      Nov 21 '18 at 16:52











    • What errors are you getting?

      – lorenzoliveto
      Nov 22 '18 at 10:07














    2












    2








    2







    If you add the width/height constraints to the buttons stack view will size it subviews based on the constraints and not the intrinsic size of buttons.






    share|improve this answer













    If you add the width/height constraints to the buttons stack view will size it subviews based on the constraints and not the intrinsic size of buttons.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 21 '18 at 16:30









    lorenzolivetolorenzoliveto

    3,06911130




    3,06911130













    • I get autolayout errors (red boxes in storyboard) when manually specifying width and height of UIButton. Why should that occur?

      – Deepak Sharma
      Nov 21 '18 at 16:34













    • Because UIStackView tries to add own constraints according to its distribution and alignment.

      – olejnjak
      Nov 21 '18 at 16:52











    • What errors are you getting?

      – lorenzoliveto
      Nov 22 '18 at 10:07



















    • I get autolayout errors (red boxes in storyboard) when manually specifying width and height of UIButton. Why should that occur?

      – Deepak Sharma
      Nov 21 '18 at 16:34













    • Because UIStackView tries to add own constraints according to its distribution and alignment.

      – olejnjak
      Nov 21 '18 at 16:52











    • What errors are you getting?

      – lorenzoliveto
      Nov 22 '18 at 10:07

















    I get autolayout errors (red boxes in storyboard) when manually specifying width and height of UIButton. Why should that occur?

    – Deepak Sharma
    Nov 21 '18 at 16:34







    I get autolayout errors (red boxes in storyboard) when manually specifying width and height of UIButton. Why should that occur?

    – Deepak Sharma
    Nov 21 '18 at 16:34















    Because UIStackView tries to add own constraints according to its distribution and alignment.

    – olejnjak
    Nov 21 '18 at 16:52





    Because UIStackView tries to add own constraints according to its distribution and alignment.

    – olejnjak
    Nov 21 '18 at 16:52













    What errors are you getting?

    – lorenzoliveto
    Nov 22 '18 at 10:07





    What errors are you getting?

    – lorenzoliveto
    Nov 22 '18 at 10:07













    1














    For this purpose I usually use the contentEdgeInsets property. If it is not sufficient, you would need to add some autolayout constraints.






    share|improve this answer






























      1














      For this purpose I usually use the contentEdgeInsets property. If it is not sufficient, you would need to add some autolayout constraints.






      share|improve this answer




























        1












        1








        1







        For this purpose I usually use the contentEdgeInsets property. If it is not sufficient, you would need to add some autolayout constraints.






        share|improve this answer















        For this purpose I usually use the contentEdgeInsets property. If it is not sufficient, you would need to add some autolayout constraints.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 '18 at 23:53

























        answered Nov 21 '18 at 16:50









        olejnjakolejnjak

        458312




        458312






























            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%2f53416177%2fincrease-area-of-uibutton-in-uistackview%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

            Costa Masnaga

            Fotorealismo

            Sidney Franklin