ElaWorkshop / TagListView

Simple and highly customizable iOS tag list view, in Swift.
MIT License
2.64k stars 493 forks source link

Tag sublayers are not properly sized #140

Closed raysarebest closed 5 years ago

raysarebest commented 7 years ago

When adding a sublayer to a tag when a tag is created, the sublayers are sized differently when the tag is rendered. For example, when adding a CAGradientLayer in my app with this code:

let tag = tagView.addTag(text)
tag.paddingX = 12
tag.paddingY = 14
tag.enableRemoveButton = true
tag.cornerRadius = searchBar.layer.cornerRadius
let gradient = CAGradientLayer()
gradient.colors = [#colorLiteral(red: 0.9803921569, green: 0.9803921569, blue: 0, alpha: 1).cgColor, #colorLiteral(red: 0.9803921569, green: 0.8156862745, blue: 0, alpha: 1).cgColor]
gradient.startPoint = .zero
gradient.endPoint = CGPoint(x: 1, y: 1)
gradient.frame = tag.layer.frame
tag.layer.addSublayer(gradient)

The tag appears on my screen like this:

Gradient oddly sized

I suspect this is because the tag view generates its size sometime after this code runs, so the values for the tag's layer's frame and bounds are updated sometime after this, but its sublayers are not

NOTE: This only seems to happen when paddingX and/or paddingY is set