I want to set the border of a UITextView
or a UILabel
in a Storyboard.
Can it be done?
Programmatically, it is setBorderColor
and setBorderWidth
.
But can the border be set in a Storyboard?
I want to set the border of a UITextView
or a UILabel
in a Storyboard.
Can it be done?
Programmatically, it is setBorderColor
and setBorderWidth
.
But can the border be set in a Storyboard?
As was previously pointed out, these properties are part of a layer, not part of a view. But you can still set their values in IB. As hypercrypt pointed out, you can use User Defined Runtime Attributes. Since all views have a "layer" property, you can set "layer.borderWidth" for instance.
Here's a case, where I'm changing the cornerRadius. Works great.
UIColor
, not a CGColor
. You can still get the behavior you want (being able to set border color from Interface Builder), but you'll need a custom UIView
subclass with a UIColor
property that you set from the storyboard and code that applies that color to the border, and then you'll need to nest your views in the storyboard inside instances of that subclass. Whether this is more hassle than it's worth is left as a question for the reader.
Aug 14, 2013 at 11:04
UIView
, you can also accomplish this functionality with a category. Define a UIColor
property in the category interface, implement the setter that sets self.layer.borderColor = inputColor.CGColor
, and implement the getter to return [UIColor colorWithCGColor:self.layer.borderColor]
.
use simple code in .m,it show border in view
view.layer.cornerRadius = 5.0f;
view.layer.masksToBounds = NO;
view.layer.borderWidth = .5f;
view.layer.shadowColor = [UIColor orangeColor].CGColor;
view.layer.shadowOpacity = 0.4;
view.layer.shadowRadius = 5.0f;
If you're targeting iOS 6+ you can use the User Defined Runtime Attributes in the Identity Inspector to set any properties. Performance is not an issue for either, so it doesn't matter.