我在我的應用程式中使用 tableview 單元格重新排序控制元件,它在 iOS 14 之前運行良好,但不適用于 iOS 15。在 iOS 15 中重新排序控制元件的顏色沒有改變。
以下是我使用的代碼。那么如何在 iOS 15 中更改重新排序控制元件的顏色。
private var myReorderImage : UIImage? = nil;
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
for subViewA in cell.subviews {
if (subViewA.classForCoder.description() == "UITableViewCellReorderControl") {
for subViewB in subViewA.subviews {
if (subViewB.isKind(of: UIImageView.classForCoder())) {
let imageView = subViewB as! UIImageView;
if (myReorderImage == nil) {
let myImage = imageView.image;
myReorderImage = myImage?.withRenderingMode(UIImageRenderingMode.alwaysTemplate);
}
imageView.image = myReorderImage;
imageView.tintColor = UIColor.red;
break;
}
}
break;
}
}
}
uj5u.com熱心網友回復:
在 iOS 15 中,我嘗試自定義重新排序控制元件的圖示,但未能做到。所以我只是從 Reorder 控制元件中洗掉 UIImageview 物件。并以編程方式創建我自己的影像視圖物件并將影像設定為該影像視圖。然后將該 imageView 作為 addSubview 添加到重新排序控制元件中。它解決了我的問題。
遵循共享代碼,以便對面臨相同問題的其他人有所幫助。
private var myReorderImage : UIImage? = nil;
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
for subViewA in cell.subviews {
if (subViewA.classForCoder.description() == "UITableViewCellReorderControl") {
for subViewB in subViewA.subviews {
if (subViewB.isKind(of: UIImageView.classForCoder())) {
subViewB.removeFromSuperview()
let imageView = UIImageView()
if (self.myReorderImage == nil) {
let myImage = imageView.image
myReorderImage = myImage?.withRenderingMode(.alwaysTemplate)
}
var frame = imageView.frame
frame.origin.x = 3
frame.origin.y = 14
frame.size = CGSize(width: 21, height: 9)
self.myReorderImage = UIImage(named:"YourImage") // set your image
imageView.frame = frame
imageView.image = self.myReorderImage
subViewA.addSubview(imageView) // add imageView to reorder control
break;
}
}
break;
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/375004.html