Found a solution here in Swift: How to add a border just on the top side of a UIView
Need it in Objective-C. So I may have to Dig Swift in order to convert it and but I have not learned Swift yet.
Swift Code :
func addBorder(edges edges: UIRectEdge, colour: UIColor = UIColor.whiteColor(), thickness: CGFloat = 1) -> [UIView] {
var borders = [UIView]()
func border() -> UIView {
let border = UIView(frame: CGRectZero)
border.backgroundColor = colour
border.translatesAutoresizingMaskIntoConstraints = false
return border
}
if edges.contains(.Top) || edges.contains(.All) {
let top = border()
addSubview(top)
addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat("V:|-(0)-[top(==thickness)]",
options: [],
metrics: ["thickness": thickness],
views: ["top": top]))
addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat("H:|-(0)-[top]-(0)-|",
options: [],
metrics: nil,
views: ["top": top]))
borders.append(top)
}
if edges.contains(.Left) || edges.contains(.All) {
let left = border()
addSubview(left)
addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat("H:|-(0)-[left(==thickness)]",
options: [],
metrics: ["thickness": thickness],
views: ["left": left]))
addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat("V:|-(0)-[left]-(0)-|",
options: [],
metrics: nil,
views: ["left": left]))
borders.append(left)
}
if edges.contains(.Right) || edges.contains(.All) {
let right = border()
addSubview(right)
addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat("H:[right(==thickness)]-(0)-|",
options: [],
metrics: ["thickness": thickness],
views: ["right": right]))
addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat("V:|-(0)-[right]-(0)-|",
options: [],
metrics: nil,
views: ["right": right]))
borders.append(right)
}
if edges.contains(.Bottom) || edges.contains(.All) {
let bottom = border()
addSubview(bottom)
addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat("V:[bottom(==thickness)]-(0)-|",
options: [],
metrics: ["thickness": thickness],
views: ["bottom": bottom]))
addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat("H:|-(0)-[bottom]-(0)-|",
options: [],
metrics: nil,
views: ["bottom": bottom]))
borders.append(bottom)
}
return borders
}
P.S - I have asked the original answerer to provide it in Objective-C, but he may take sometime to respond. My Purpose to post it is that, I just want a bit quicker solution here.
Regards!