swift - How do I change a UIImage color when tapping tableview cell? -
so have been stuck on day or so. how change color of uiimage color when tapping on tableview cell? example have black image , when tap tableview cell changes image white? thank you!
i tried using code not know how implement right!
let theimageview = uiimageview(image: uiimage(named:"foo")!.imagewithrenderingmode(uiimagerenderingmode.alwaystemplate)) theimageview.tintcolor = uicolor.redcolor()
it looks have right pieces don't know call them. assign image image view in cellforrowat:
method.
func tableview(_ tableview: uitableview, cellforrowat indexpath: nsindexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecell(withidentifier: reuseidentifier, for: indexpath) cell.imageview.image = uiimage(named:"foo")!.withrenderingmode(.alwaystemplate) return cell }
then change tint color of image view in didselect
delegate method.
func tableview(_ tableview: uitableview, didselectrowat indexpath: indexpath) { if let cell = tableview.cellforrow(at: indexpath) { cell.imageview.tintcolor = newcolor } }
Comments
Post a Comment