UIButton with low alpha background but fully opaque title?










0















How can I make a UIButton with a transparent background but a non-transparent title? I tried the following



button.alpha = .5;
button.titleLabel.alpha = 1;


That did not have the desired effect. Other suggestions?










share|improve this question






















  • Subclass the button and do it internally?

    – Mike
    Jan 28 '16 at 20:31















0















How can I make a UIButton with a transparent background but a non-transparent title? I tried the following



button.alpha = .5;
button.titleLabel.alpha = 1;


That did not have the desired effect. Other suggestions?










share|improve this question






















  • Subclass the button and do it internally?

    – Mike
    Jan 28 '16 at 20:31













0












0








0








How can I make a UIButton with a transparent background but a non-transparent title? I tried the following



button.alpha = .5;
button.titleLabel.alpha = 1;


That did not have the desired effect. Other suggestions?










share|improve this question














How can I make a UIButton with a transparent background but a non-transparent title? I tried the following



button.alpha = .5;
button.titleLabel.alpha = 1;


That did not have the desired effect. Other suggestions?







ios objective-c






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 28 '16 at 20:11









helloBhelloB

93211444




93211444












  • Subclass the button and do it internally?

    – Mike
    Jan 28 '16 at 20:31

















  • Subclass the button and do it internally?

    – Mike
    Jan 28 '16 at 20:31
















Subclass the button and do it internally?

– Mike
Jan 28 '16 at 20:31





Subclass the button and do it internally?

– Mike
Jan 28 '16 at 20:31












3 Answers
3






active

oldest

votes


















1














just make only the background 0.5 alpha



button.backgroundColor = [UIColor colorWithRed:100.0/255.0 green:100.0/255.0 blue:100.0/255.0 alpha:0.5];





share|improve this answer























  • Can I do that without doing it by setting the color?

    – helloB
    Jan 28 '16 at 20:19











  • are you have background image on the button ?

    – Mohamed Helmy
    Jan 28 '16 at 20:21











  • you can read existing backgroundColor and create new background color out of it by keeping all the components same except alpha

    – ishaq
    Jan 28 '16 at 20:21


















1














Just try playing with different parts of your button.




For example, if that is the image, that you want with alpha 0.5, then try this:



[button setImage:[UIImage imageNamed:@"myImage"] forState:UIControlStateNormal];

button.imageView.alpha = 0.5;



or even this:



button.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"myImage"]];

button.backgroundColor = [button.backgroundColor colorWithAlphaComponent:0.5];



You can even add alpha directly onto UIImage --
How to set the opacity/alpha of a UIImage?



The above link would help if you are setting the image via:



[button setBackgroundImage:[UIImage imageNamed:@"myImage"] forState:UIControlStateNormal];



I don't know other solutions, though. Hope this helps.






share|improve this answer
































    0














    you can use this:
    swift button.backgroundColor = UIColor.white.withAlphaComponent(0.7)






    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%2f35071090%2fuibutton-with-low-alpha-background-but-fully-opaque-title%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      just make only the background 0.5 alpha



      button.backgroundColor = [UIColor colorWithRed:100.0/255.0 green:100.0/255.0 blue:100.0/255.0 alpha:0.5];





      share|improve this answer























      • Can I do that without doing it by setting the color?

        – helloB
        Jan 28 '16 at 20:19











      • are you have background image on the button ?

        – Mohamed Helmy
        Jan 28 '16 at 20:21











      • you can read existing backgroundColor and create new background color out of it by keeping all the components same except alpha

        – ishaq
        Jan 28 '16 at 20:21















      1














      just make only the background 0.5 alpha



      button.backgroundColor = [UIColor colorWithRed:100.0/255.0 green:100.0/255.0 blue:100.0/255.0 alpha:0.5];





      share|improve this answer























      • Can I do that without doing it by setting the color?

        – helloB
        Jan 28 '16 at 20:19











      • are you have background image on the button ?

        – Mohamed Helmy
        Jan 28 '16 at 20:21











      • you can read existing backgroundColor and create new background color out of it by keeping all the components same except alpha

        – ishaq
        Jan 28 '16 at 20:21













      1












      1








      1







      just make only the background 0.5 alpha



      button.backgroundColor = [UIColor colorWithRed:100.0/255.0 green:100.0/255.0 blue:100.0/255.0 alpha:0.5];





      share|improve this answer













      just make only the background 0.5 alpha



      button.backgroundColor = [UIColor colorWithRed:100.0/255.0 green:100.0/255.0 blue:100.0/255.0 alpha:0.5];






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Jan 28 '16 at 20:17









      Mohamed HelmyMohamed Helmy

      456618




      456618












      • Can I do that without doing it by setting the color?

        – helloB
        Jan 28 '16 at 20:19











      • are you have background image on the button ?

        – Mohamed Helmy
        Jan 28 '16 at 20:21











      • you can read existing backgroundColor and create new background color out of it by keeping all the components same except alpha

        – ishaq
        Jan 28 '16 at 20:21

















      • Can I do that without doing it by setting the color?

        – helloB
        Jan 28 '16 at 20:19











      • are you have background image on the button ?

        – Mohamed Helmy
        Jan 28 '16 at 20:21











      • you can read existing backgroundColor and create new background color out of it by keeping all the components same except alpha

        – ishaq
        Jan 28 '16 at 20:21
















      Can I do that without doing it by setting the color?

      – helloB
      Jan 28 '16 at 20:19





      Can I do that without doing it by setting the color?

      – helloB
      Jan 28 '16 at 20:19













      are you have background image on the button ?

      – Mohamed Helmy
      Jan 28 '16 at 20:21





      are you have background image on the button ?

      – Mohamed Helmy
      Jan 28 '16 at 20:21













      you can read existing backgroundColor and create new background color out of it by keeping all the components same except alpha

      – ishaq
      Jan 28 '16 at 20:21





      you can read existing backgroundColor and create new background color out of it by keeping all the components same except alpha

      – ishaq
      Jan 28 '16 at 20:21













      1














      Just try playing with different parts of your button.




      For example, if that is the image, that you want with alpha 0.5, then try this:



      [button setImage:[UIImage imageNamed:@"myImage"] forState:UIControlStateNormal];

      button.imageView.alpha = 0.5;



      or even this:



      button.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"myImage"]];

      button.backgroundColor = [button.backgroundColor colorWithAlphaComponent:0.5];



      You can even add alpha directly onto UIImage --
      How to set the opacity/alpha of a UIImage?



      The above link would help if you are setting the image via:



      [button setBackgroundImage:[UIImage imageNamed:@"myImage"] forState:UIControlStateNormal];



      I don't know other solutions, though. Hope this helps.






      share|improve this answer





























        1














        Just try playing with different parts of your button.




        For example, if that is the image, that you want with alpha 0.5, then try this:



        [button setImage:[UIImage imageNamed:@"myImage"] forState:UIControlStateNormal];

        button.imageView.alpha = 0.5;



        or even this:



        button.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"myImage"]];

        button.backgroundColor = [button.backgroundColor colorWithAlphaComponent:0.5];



        You can even add alpha directly onto UIImage --
        How to set the opacity/alpha of a UIImage?



        The above link would help if you are setting the image via:



        [button setBackgroundImage:[UIImage imageNamed:@"myImage"] forState:UIControlStateNormal];



        I don't know other solutions, though. Hope this helps.






        share|improve this answer



























          1












          1








          1







          Just try playing with different parts of your button.




          For example, if that is the image, that you want with alpha 0.5, then try this:



          [button setImage:[UIImage imageNamed:@"myImage"] forState:UIControlStateNormal];

          button.imageView.alpha = 0.5;



          or even this:



          button.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"myImage"]];

          button.backgroundColor = [button.backgroundColor colorWithAlphaComponent:0.5];



          You can even add alpha directly onto UIImage --
          How to set the opacity/alpha of a UIImage?



          The above link would help if you are setting the image via:



          [button setBackgroundImage:[UIImage imageNamed:@"myImage"] forState:UIControlStateNormal];



          I don't know other solutions, though. Hope this helps.






          share|improve this answer















          Just try playing with different parts of your button.




          For example, if that is the image, that you want with alpha 0.5, then try this:



          [button setImage:[UIImage imageNamed:@"myImage"] forState:UIControlStateNormal];

          button.imageView.alpha = 0.5;



          or even this:



          button.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"myImage"]];

          button.backgroundColor = [button.backgroundColor colorWithAlphaComponent:0.5];



          You can even add alpha directly onto UIImage --
          How to set the opacity/alpha of a UIImage?



          The above link would help if you are setting the image via:



          [button setBackgroundImage:[UIImage imageNamed:@"myImage"] forState:UIControlStateNormal];



          I don't know other solutions, though. Hope this helps.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 23 '17 at 11:59









          Community

          11




          11










          answered Jan 28 '16 at 20:32









          OlDorOlDor

          1,046414




          1,046414





















              0














              you can use this:
              swift button.backgroundColor = UIColor.white.withAlphaComponent(0.7)






              share|improve this answer



























                0














                you can use this:
                swift button.backgroundColor = UIColor.white.withAlphaComponent(0.7)






                share|improve this answer

























                  0












                  0








                  0







                  you can use this:
                  swift button.backgroundColor = UIColor.white.withAlphaComponent(0.7)






                  share|improve this answer













                  you can use this:
                  swift button.backgroundColor = UIColor.white.withAlphaComponent(0.7)







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 14 '18 at 13:00









                  m.alqadim.alqadi

                  13117




                  13117



























                      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%2f35071090%2fuibutton-with-low-alpha-background-but-fully-opaque-title%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







                      這個網誌中的熱門文章

                      What does pagestruct do in Eviews?

                      Dutch intervention in Lombok and Karangasem

                      Channel Islands