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:
here is the screenshot of the 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
|
show 4 more comments
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:
here is the screenshot of the 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
Try usingself.layer.masksToBounds = true
instead ofclipsToBounds
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
|
show 4 more comments
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:
here is the screenshot of the 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
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:
here is the screenshot of the 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
ios swift uibutton
edited Nov 8 at 14:43
asked Nov 8 at 14:25


Alexander Espiritu
114
114
Try usingself.layer.masksToBounds = true
instead ofclipsToBounds
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
|
show 4 more comments
Try usingself.layer.masksToBounds = true
instead ofclipsToBounds
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
|
show 4 more comments
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
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.
add a comment |
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
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.
add a comment |
up vote
0
down vote
I try your code and it works fine, Set your UIButton as Custom type
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.
add a comment |
up vote
0
down vote
up vote
0
down vote
I try your code and it works fine, Set your UIButton as Custom type
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.
I try your code and it works fine, Set your UIButton as Custom type
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.
edited Nov 8 at 17:13
answered Nov 8 at 17:06


Raul Mantilla
595
595
add a comment |
add a comment |
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%2f53209728%2fhow-to-use-uibutton-with-custom-class%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
Try using
self.layer.masksToBounds = true
instead ofclipsToBounds
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