我有一个UILabel,它使用了一个与背景相同颜色的边框,并将其半遮半掩,以创造一个漂亮的视觉效果。但问题是,在边框的外部,仍然有一小部分标签的背景色,但很明显。
边框并没有覆盖整个标签。
遗憾的是,改变边框宽度也没有任何改变。
下面是一张图片,放大后你就可以看到了。
我的代码如下
iconLbl.frame = CGRectMake(theWidth/2-20, bottomView.frame.minY-20, 40, 40)
iconLbl.font = UIFont.fontAwesomeOfSize(23)
iconLbl.text = String.fontAwesomeIconWithName(.Info)
iconLbl.layer.masksToBounds = true
iconLbl.layer.cornerRadius = iconLbl.frame.size.width/2
iconLbl.layer.borderWidth = 5
iconLbl.layer.borderColor = topBackgroundColor.CGColor
iconLbl.backgroundColor = UIColor.cyanColor()
iconLbl.textColor = UIColor.whiteColor()
是我遗漏了什么吗 还是我得想出另一个办法来达到这个效果?
谢谢!
EDIT:目前我试过的东西列表!
EDIT 2:
没有找到修复方法!我使用了一个变通的方法,将这个方法扩展到我的UIViewController上。
func makeFakeBorder(inputView:UIView,width:CGFloat,color:UIColor) -> UIView {
let fakeBorder = UIView()
fakeBorder.frame = CGRectMake(inputView.frame.origin.x-width, inputView.frame.origin.y-width, inputView.frame.size.width+width*2, inputView.frame.size.height+width*2)
fakeBorder.backgroundColor = color
fakeBorder.clipsToBounds = true
fakeBorder.layer.cornerRadius = fakeBorder.frame.size.width/2
fakeBorder.addSubview(inputView)
inputView.center = CGPointMake(fakeBorder.frame.size.width/2, fakeBorder.frame.size.height/2)
return fakeBorder
}