Reputation:
I have a UICollectionView
. It is filled with cells which include an image view and a label.
When one taps on a cell the text just disappears. How can I stop this from happening?
Extra information:
The collection view is within a container connected to a baseVC.
Cells and most of their content are added in its xib file. Everything shows up correctly. Expect when tapping, where text disappears and then reappears.
Also note that the label does not disappear, only the text.
The custom text is added when calling a cells: func setup(profImage: String, contentView: String, titleLabel: String, subtitleLabel: String)
and even when disabling the text from being added the default labels still disappear on tap.
Upvotes: 3
Views: 1090
Reputation: 15679
I would make sure the label is added to the contentView
of the cell and not just the "top-most" view of the cell. Maybe the way the xib
is setup is not right. Make sure it is UICollectionViewCell
in the xib etc. You could also post pictures of how you have setup the xib
.
Also, to debug, I would remove any code that deals with the cell that is not revolved around the label (for example, remove the animations until you fixed the bug). That will allow you to zone in on the issue. Or, another way, just begin from scratch and re-create the cell (with only the label). Getting a label to display is not rocket science, but you can make it rocket science if you do not build what is going on step-by-step.
Another potential issue is layout. Is the layout done right? And maybe it breaks (for some reason) when you highlight.
Upvotes: 2
Reputation: 1361
Try using UILabel's highlighted text color property:
The highlight color applied to the label’s text.
@property(nonatomic, strong) UIColor *highlightedTextColor;
Upvotes: 1
Reputation: 33
Have you tried resetting the text after the animation is completed ?
let cell = collectionView.cellForItem(at: indexPath)
let thumbnail = postArray[indexPath.item].media[0].thumbnail!
let date = ConvertDate(mediaTimestamp: postArray[indexPath.row].media[0].postTimeStamp!, isItForP3: false).getDate!
UIView.animatewithDuration: 0.1, delay: 0.0, options: UIView.AnimationOptions.curveLinear, animations: {
cell!.transform = CGAffineTransform.identity.scaledBy(x: 1.0, y: 1.0)
}, completion: { (finished: Bool) in
if finished {
cell.setup(profImage: "\(self.postArray[indexPath.item].user.profileImageUrlString!)", contentView: thumbnail, titleLabel: postArray[indexPath.item].user.username!, subtitleLabel: date)
}
})
There's probably a better way to do this, though.
Upvotes: 0