1

I have required to set border color UIView using User Defined Runtime Attributesin identity inspector. By default Color isBlackColor`. If any constraints is available in iOS then tell me.

TylerH
  • 20,799
  • 66
  • 75
  • 101

4 Answers4

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,

enter image description here

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
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
1

try this code it will help you:

yourViewNAme.layer.borderWidth = 1;
    yourViewNAme.layer.borderColor = [UIColor DesiredColour].CGColor;