AKPickerView-Swift
AKPickerView-Swift copied to clipboard
Selected Item Highlight Text
The highlightedFont is set to bold. However, when you select another item the previous item remains bold and the new item's font does not become bold. When the first item is scrolled off the screen it is redrawn and the font is set to the system font rather than the bold font.
It would appear that the issue is with the selected implementation of the AKCollectionViewCell. Changing this from _selected to selected removing the initialisation to false and updating the setting in the cellForRowAtIndexPath fixed the issue for me.
Has anyone else had this issue? Could it be the way I am initialising the picker or is this a genuine issue others have experienced?
Hey. I've had the same struggle, that's why I came to the thread.
There was a notice in the readme file, that you have to call pickerView.reloadData()
whenever you change its settings. Solved the issue for me.
Still has a problem like all the reload methods do. The view blinks to redraw. This blink also takes away the swiping animation so I guess calling the reload method is not the best solution here.
Can you please show your solution?
Came here for the same issue.
Based on Scott mentioned, I think I manage to replicate his solution...
In the AKPickerView.swift
file, find the private class AKCollectionViewCell : UICollectionViewCell
initialisation (line 57 for me)
Where you see var _selected : Bool = false {...}
I changed it to
override var selected: Bool {
didSet(selected) {
let animation = CATransition()
animation.type = kCATransitionFade
animation.duration = 0.15
self.label.layer.addAnimation(animation, forKey: "")
self.label.font = self.selected ? self.highlightedFont : self.font
}
}
Then further down in the public func collectionView( cellforItemAtInexPath)
(line 518 for me) you will see an error with cell._selected = (indexPath.item == self.selectedItem)
.
I just then update cell._selected
with the new cell.selected
Built the code, and now it seems to be behaving as expected. :)
Same problem here, @simonarcher your solution worked!
Also note: call .selectItem(index, animated: false)
in viewDidLoad
. This including changes mentioned above did the trick for me.
this is still not fixed, i am struggling on finding a fix