swift标签只剩下边框 [英] swift label only border left
本文介绍了swift标签只剩下边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
早上好,
我有这样的桌面视图:
i have a tableview like this:
示例:单元格中的
我在右侧有一个红色文本标签。剩下的
我包含一个像灰线的图像。
Example: in cell one i have got an red text label on the right side. left from it i include an image like a grey line.
使用此代码我可以设置一个完整的绿色边框:
with this code i can set a complete green border:
cell.Label.layer.borderWidth = 0.5
cell.Label.layer.borderColor = UIColor.greenColor().CGColor
我可以在此文本标签的左侧仅设置边框吗?
i使用swift ios8 - 所以,我需要一个快捷的解决方案
can i set only a border on the left side from this text label? i use swift ios8 - so, i need a swift solution
推荐答案
这是你可以添加到你的项目的扩展:
Here is an extension you can add to your project:
extension CALayer {
func addBorder(edge: UIRectEdge, color: UIColor, thickness: CGFloat) {
var border = CALayer()
switch edge {
case UIRectEdge.Top:
border.frame = CGRectMake(0, 0, CGRectGetHeight(self.frame), thickness)
break
case UIRectEdge.Bottom:
border.frame = CGRectMake(0, CGRectGetHeight(self.frame) - thickness, UIScreen.mainScreen().bounds.width, thickness)
break
case UIRectEdge.Left:
border.frame = CGRectMake(0, 0, thickness, CGRectGetHeight(self.frame))
break
case UIRectEdge.Right:
border.frame = CGRectMake(CGRectGetWidth(self.frame) - thickness, 0, thickness, CGRectGetHeight(self.frame))
break
default:
break
}
border.backgroundColor = color.CGColor;
self.addSublayer(border)
}
}
并使用它:
cell.Label.layer.addBorder(UIRectEdge.Top, color: UIColor.greenColor(), thickness: 0.5)
这篇关于swift标签只剩下边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文