I have required to set border color UIView
using User Defined Runtime Attributesin identity inspector. By default Color is
BlackColor`. If any constraints is available in iOS then tell me.
Asked
Active
Viewed 2,080 times
1

TylerH
- 20,799
- 66
- 75
- 101

Hiren Dholariya
- 19
- 5
-
what do you mean by runtime constraints? – Tyson Vignesh May 04 '16 at 06:49
-
http://stackoverflow.com/questions/14792238/uiviews-border-color-in-interface-builder-doesnt-work – Tyson Vignesh May 04 '16 at 06:59
4 Answers
3
you can set border color like,
yourView.layer.borderColor = [UIColor orangeColor].CGColor;
yourView.layer.borderWidth = 1.0; //you have to give width to make border visible
Update according to comment :
you can set runtime attributes for view like below screenshot,
But it will display black border because layer uses cgcolor
and you can't get cgcolor reference in interface builder. so you can't set layer color directly as runtime attribute. It's better to set from code as i have mentioned above.
If you hardly want to set color from runtime attribute only then you can try Peter Deweese's answer.

TylerH
- 20,799
- 66
- 75
- 101

Ketan Parmar
- 27,092
- 9
- 50
- 75
-
But I have required to add borderColor using Runtime Constraints. That's not properly answers for me. – Hiren Dholariya May 04 '16 at 06:42
-
means? what you want exactly ? explain it because i am not getting your need! – Ketan Parmar May 04 '16 at 06:50
-
In XCode -> Attribute Inspector -> User Defined Runtime Attributes -> here we can also set Constraints for the view. – Hiren Dholariya May 04 '16 at 06:53
-
-
There are no option available in `attribute inspector` i think. I think you are saying about `user define run time attribute` from `identity inspector`. is it so ? – Ketan Parmar May 04 '16 at 06:56
-
3
This will work -
UIView *view = [[UIView alloc] init];
...
//Add a Your Color border
view.layer.borderColor = [UIColor colorWithWhite:1.0f alpha:1.0f].CGColor;
view.layer.borderWidth = 1.0f; //make border 1px thick

raj
- 63
- 5
1
please try this code, ViewController.h
declare @property (weak, nonatomic) IBOutlet UIView *searchView;
In ViewController.m
.
viewDidLoad
Method:
searchView.layer.cornerRadius = 8.0f;
searchView.layer.borderColor = [UIColor lightGrayColor].CGColor;
searchView.layer.borderWidth = 0.8f;
searchView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
searchView.layer.shadowOpacity = 0.8f;
searchView.layer.shadowRadius = 3.0f;
searchView.layer.shadowOffset =CGSizeMake(2.0f, 2.0f);

TylerH
- 20,799
- 66
- 75
- 101

Iyyappan Ravi
- 3,205
- 2
- 16
- 30
-
But I have required to add borderColor using Runtime Constraints. That's not properly answers for me. – Hiren Dholariya May 04 '16 at 06:45
-
see the link, its clearly showed you need, https://spin.atomicobject.com/2014/05/30/xcode-runtime-attributes/ – Iyyappan Ravi May 04 '16 at 06:59
1
try this code it will help you:
yourViewNAme.layer.borderWidth = 1;
yourViewNAme.layer.borderColor = [UIColor DesiredColour].CGColor;
-
But I have required to add borderColor using Runtime Constraints. That's not properly answers for me. – Hiren Dholariya May 04 '16 at 06:46