I have a UICollectionView wherein the cells contain UILabels and have a backgroundView that is a UIImage. The label backgrounds are clear. My problem is that segments of the text can become difficult to read when there is little contrast between the text color and the colors in the area of the image over which the text appears. I suspect that there are techniques which can be used to help with this (White text with a black border perhaps? Possible? How?). Would someone please advise me?
First Edit:
I tried @EssamMohamed / @AbdelahadDarwish answer but it didn't work. I might be doing something wrong.
I am using a .xib file and a custom class. Here is the custom class:
class PointOfInterestCell: UICollectionViewCell {
@IBOutlet weak var nameLabel: UILabel! {
didSet {
//nameLabel.textColor = UIColor.tohTerracotaColor()
}
}
@IBOutlet weak var distanceLabel: UILabel! {
didSet {
let strokeTextAttributes = [
NSStrokeColorAttributeName : UIColor.black,
NSForegroundColorAttributeName : UIColor.white,
NSStrokeWidthAttributeName : -1.0,
] as [String : Any]
let text = distanceLabel.text ?? "????"
distanceLabel.attributedText = NSAttributedString(string: text, attributes: strokeTextAttributes)
}
}
}