Screenshot:
if I use it in code then receive this message:
like: Value of type 'UIView' has no member cornerRadius
What is wrong? Yesterday I didn't have this problem
Asked
Active
Viewed 1,871 times
1

Sivajee Battina
- 4,124
- 2
- 22
- 45

Martin Gut
- 31
- 1
- 6
3 Answers
3
You need to use Button's layer to set border property. e.g:
button.layer.cornerRadius = button.frame.height / 2.0
button.layer.masksToBounds = true
button.layer.borderColor = UIColor.lightGray.cgColor
button.layer.borderWidth = 1.0
OR
Add this extension to get these options in storyboard.
extension UIView {
@IBInspectable var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
}
}
@IBInspectable var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set {
layer.borderWidth = newValue
}
}
@IBInspectable var borderColor: UIColor? {
get {
let color = UIColor.init(cgColor: layer.borderColor!)
return color
}
set {
layer.borderColor = newValue?.cgColor
}
}
@IBInspectable var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set {
layer.shadowColor = UIColor.black.cgColor
layer.shadowOffset = CGSize(width: 0, height: 2)
layer.shadowOpacity = 0.4
layer.shadowRadius = shadowRadius
}
}
}

RajeshKumar R
- 15,445
- 2
- 38
- 70
-
Yes, right, there was a mistake. But why I don't have this options in Storyboard ? – Martin Gut Mar 14 '17 at 10:55
-
By default these options are not editable in storyboard. If you want you can add a `UIView extension` to get these options in storyboard. Check updated answer. – RajeshKumar R Mar 14 '17 at 11:00
-
1Thanks!!! I used library "Material" and It has this one by default, yesterday I removed this library and it happened) I thought this are default settings in ios ( I'm new in ios programming ) – Martin Gut Mar 14 '17 at 11:24
0
It should be like this
#import <QuartzCore/QuartzCore.h>
[[myButton layer] setBorderWidth:2.0f];
[[myButton layer] setBorderColor:[UIColor greenColor].CGColor];
myButton.layer.cornerRadius = myButton.frame.height / 2.0;
For ref:

Community
- 1
- 1

Rajesh Dharani
- 285
- 4
- 20
0
You cannot set CALayer properties directly to UIElement. Instead, need to use .layer property.
Example:
button.layer.cornerRadius = button.frame.height/ 2.0
button.layer.maskToBounds = true

Sivajee Battina
- 4,124
- 2
- 22
- 45