Borders not covering background

倾然丶 夕夏残阳落幕 提交于 2019-12-10 20:21:35

问题


I've got a UILabel is using a border the same color as a background which it is half obscuring, to create a nice visual effect. However the problem is that there is still a tiny, yet noticeable, sliver of the label's background color on the OUTSIDE of the border.

The border is not covering the whole label!

Changing the border width doesn't change anything either, sadly.

Here's a picture of what's going on, enlarged so you can see it:

And my code follows:

        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()

Is there something I'm missing? Or am I going to have to figure out another to achieve this effect?

Thanks!

EDIT: List of things I've tried so far!

  • Changing layer.borderWidth
  • Fussing around with clipsToBounds/MasksToBounds
  • Playing around the the layer.frame
  • Playing around with an integral frame

EDIT 2:

No fix was found! I used a workaround by extending this method on to my 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
    }

来源:https://stackoverflow.com/questions/33350689/borders-not-covering-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!