How to use UIButton with Custom Class?











up vote
0
down vote

favorite












I'm currently working on an Application and my custom class doesn't seem to reflect on the UIButton even though I could select the class "RoundedButton". Here is the screenshot of my application:



Appscreenshot
here is the screenshot of the class name setting:



class name setting



and here is my code for the custom class:



class RoundedButton: UIButton {
override func layoutSubviews() {
super.layoutSubviews()
let radius: CGFloat = self.bounds.size.height / 10.0
self.layer.cornerRadius = radius
self.clipsToBounds = true
}
}


I've sifted through other sites but I can't seem to get it to work.










share|improve this question
























  • Try using self.layer.masksToBounds = true instead of clipsToBounds on the view.
    – D V
    Nov 8 at 14:29










  • how are you loading/using the buttons? have you definitely set the class to the right thing?
    – Scriptable
    Nov 8 at 14:30










  • I tried using self.layer.masksToBounds but it's still not working. @DV
    – Alexander Espiritu
    Nov 8 at 14:33












  • Yes, I set the class to "Rounded Button" in the Identity Inspector of the UIButton. @Scriptable
    – Alexander Espiritu
    Nov 8 at 14:34












  • can you take a screenshoot of class name setting
    – Sh_Khan
    Nov 8 at 14:39

















up vote
0
down vote

favorite












I'm currently working on an Application and my custom class doesn't seem to reflect on the UIButton even though I could select the class "RoundedButton". Here is the screenshot of my application:



Appscreenshot
here is the screenshot of the class name setting:



class name setting



and here is my code for the custom class:



class RoundedButton: UIButton {
override func layoutSubviews() {
super.layoutSubviews()
let radius: CGFloat = self.bounds.size.height / 10.0
self.layer.cornerRadius = radius
self.clipsToBounds = true
}
}


I've sifted through other sites but I can't seem to get it to work.










share|improve this question
























  • Try using self.layer.masksToBounds = true instead of clipsToBounds on the view.
    – D V
    Nov 8 at 14:29










  • how are you loading/using the buttons? have you definitely set the class to the right thing?
    – Scriptable
    Nov 8 at 14:30










  • I tried using self.layer.masksToBounds but it's still not working. @DV
    – Alexander Espiritu
    Nov 8 at 14:33












  • Yes, I set the class to "Rounded Button" in the Identity Inspector of the UIButton. @Scriptable
    – Alexander Espiritu
    Nov 8 at 14:34












  • can you take a screenshoot of class name setting
    – Sh_Khan
    Nov 8 at 14:39















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm currently working on an Application and my custom class doesn't seem to reflect on the UIButton even though I could select the class "RoundedButton". Here is the screenshot of my application:



Appscreenshot
here is the screenshot of the class name setting:



class name setting



and here is my code for the custom class:



class RoundedButton: UIButton {
override func layoutSubviews() {
super.layoutSubviews()
let radius: CGFloat = self.bounds.size.height / 10.0
self.layer.cornerRadius = radius
self.clipsToBounds = true
}
}


I've sifted through other sites but I can't seem to get it to work.










share|improve this question















I'm currently working on an Application and my custom class doesn't seem to reflect on the UIButton even though I could select the class "RoundedButton". Here is the screenshot of my application:



Appscreenshot
here is the screenshot of the class name setting:



class name setting



and here is my code for the custom class:



class RoundedButton: UIButton {
override func layoutSubviews() {
super.layoutSubviews()
let radius: CGFloat = self.bounds.size.height / 10.0
self.layer.cornerRadius = radius
self.clipsToBounds = true
}
}


I've sifted through other sites but I can't seem to get it to work.







ios swift uibutton






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 14:43

























asked Nov 8 at 14:25









Alexander Espiritu

114




114












  • Try using self.layer.masksToBounds = true instead of clipsToBounds on the view.
    – D V
    Nov 8 at 14:29










  • how are you loading/using the buttons? have you definitely set the class to the right thing?
    – Scriptable
    Nov 8 at 14:30










  • I tried using self.layer.masksToBounds but it's still not working. @DV
    – Alexander Espiritu
    Nov 8 at 14:33












  • Yes, I set the class to "Rounded Button" in the Identity Inspector of the UIButton. @Scriptable
    – Alexander Espiritu
    Nov 8 at 14:34












  • can you take a screenshoot of class name setting
    – Sh_Khan
    Nov 8 at 14:39




















  • Try using self.layer.masksToBounds = true instead of clipsToBounds on the view.
    – D V
    Nov 8 at 14:29










  • how are you loading/using the buttons? have you definitely set the class to the right thing?
    – Scriptable
    Nov 8 at 14:30










  • I tried using self.layer.masksToBounds but it's still not working. @DV
    – Alexander Espiritu
    Nov 8 at 14:33












  • Yes, I set the class to "Rounded Button" in the Identity Inspector of the UIButton. @Scriptable
    – Alexander Espiritu
    Nov 8 at 14:34












  • can you take a screenshoot of class name setting
    – Sh_Khan
    Nov 8 at 14:39


















Try using self.layer.masksToBounds = true instead of clipsToBounds on the view.
– D V
Nov 8 at 14:29




Try using self.layer.masksToBounds = true instead of clipsToBounds on the view.
– D V
Nov 8 at 14:29












how are you loading/using the buttons? have you definitely set the class to the right thing?
– Scriptable
Nov 8 at 14:30




how are you loading/using the buttons? have you definitely set the class to the right thing?
– Scriptable
Nov 8 at 14:30












I tried using self.layer.masksToBounds but it's still not working. @DV
– Alexander Espiritu
Nov 8 at 14:33






I tried using self.layer.masksToBounds but it's still not working. @DV
– Alexander Espiritu
Nov 8 at 14:33














Yes, I set the class to "Rounded Button" in the Identity Inspector of the UIButton. @Scriptable
– Alexander Espiritu
Nov 8 at 14:34






Yes, I set the class to "Rounded Button" in the Identity Inspector of the UIButton. @Scriptable
– Alexander Espiritu
Nov 8 at 14:34














can you take a screenshoot of class name setting
– Sh_Khan
Nov 8 at 14:39






can you take a screenshoot of class name setting
– Sh_Khan
Nov 8 at 14:39














1 Answer
1






active

oldest

votes

















up vote
0
down vote













I try your code and it works fine, Set your UIButton as Custom type



enter image description here




Sometimes Xcode does not save the UIButton Custom Class correctly, try restarting Xcode and check if the class RoundedButton is still selected for that Button.







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',
    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%2f53209728%2fhow-to-use-uibutton-with-custom-class%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








    up vote
    0
    down vote













    I try your code and it works fine, Set your UIButton as Custom type



    enter image description here




    Sometimes Xcode does not save the UIButton Custom Class correctly, try restarting Xcode and check if the class RoundedButton is still selected for that Button.







    share|improve this answer



























      up vote
      0
      down vote













      I try your code and it works fine, Set your UIButton as Custom type



      enter image description here




      Sometimes Xcode does not save the UIButton Custom Class correctly, try restarting Xcode and check if the class RoundedButton is still selected for that Button.







      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        I try your code and it works fine, Set your UIButton as Custom type



        enter image description here




        Sometimes Xcode does not save the UIButton Custom Class correctly, try restarting Xcode and check if the class RoundedButton is still selected for that Button.







        share|improve this answer














        I try your code and it works fine, Set your UIButton as Custom type



        enter image description here




        Sometimes Xcode does not save the UIButton Custom Class correctly, try restarting Xcode and check if the class RoundedButton is still selected for that Button.








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 8 at 17:13

























        answered Nov 8 at 17:06









        Raul Mantilla

        595




        595






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53209728%2fhow-to-use-uibutton-with-custom-class%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

            how to define a CAPL function taking a sysvar argument

            Schultheiß

            Extract exact text in tags