Skip to content

Instantly share code, notes, and snippets.

@zachmayberry
Created April 28, 2015 15:13
Show Gist options
  • Save zachmayberry/50e29bdf65f8bb7dd37b to your computer and use it in GitHub Desktop.
Save zachmayberry/50e29bdf65f8bb7dd37b to your computer and use it in GitHub Desktop.
Add borders to UIView
- (void)addBorders {
// Set thickness
NSInteger borderThickness = 1;
// Comment out each border not needed
UIView *topBorder = [UIView new];
topBorder.backgroundColor = [UIColor lightGrayColor];
topBorder.frame = CGRectMake(0, 0, myView.frame.size.width, borderThickness);
[myView addSubview:topBorder];
UIView *bottomBorder = [UIView new];
bottomBorder.backgroundColor = [UIColor lightGrayColor];
bottomBorder.frame = CGRectMake(0, myView.frame.size.height - borderThickness, myView.frame.size.width, borderThickness);
[myView addSubview:bottomBorder];
UIView *leftBorder = [UIView new];
leftBorder.backgroundColor = [UIColor lightGrayColor];
leftBorder.frame = CGRectMake(0, 0, borderThickness, myView.frame.size.height);
[myView addSubview:leftBorder];
UIView *rightBorder = [UIView new];
rightBorder.backgroundColor = [UIColor lightGrayColor];
rightBorder.frame = CGRectMake(myView.frame.size.width - borderThickness, 0, borderThickness, myView.frame.size.height);
[myView addSubview:rightBorder];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment