2016-04-08 44 views
1

我搜索了很多,但我只找到如何更改刪除按鈕。我必須改變的是圓形小按鈕的顏色。那可能嗎?更改編輯表中紅色按鈕的顏色

enter image description here

+0

嘗試循環通過子視圖,看看那個按鈕類是什麼! –

回答

0

那紅色按鈕是不是一個按鈕。這是一個圖像。

您需要在UITableViewCell中查找子視圖,並在子視圖爲UITableViewCellEditControl時,將視圖轉換爲圖像視圖,然後更改其中的圖像。

您需要有一個類似於紅色圖像的自定義彩色圖像。

for (UIView *subv in cell.subviews){ 
    if ([NSStringFromClass([subv class]) isEqualToString:@"UITableViewCellEditControl"]) { 

       for (UIView *imgV in subv.subviews){ { 

        if(imgV isKindOfClass:[UIImageView class]]){ 
        UIImageView *imgView = (UIImageView *)imgV; 
        imgView.image=[UIImage imageNamed:@"blue.png"]; 
        imgV.backgroundColor=[UIColor blueColor]; 
        NSLog(@"subview-subview name is %@",NSStringFromClass([imgV class])); 
       } 

       } 

      } 
} 

enter image description here

請注意,改變私有子視圖是不是一個好的做法。此方法可能無法在下一次iOS更新中使用 - 歸功於@rmaddy。

另一個解決方法是設計自己的自定義單元格。

+0

這是危險的,易碎的代碼。這段代碼假定'UITableViewCellEditControl'的每個子視圖都是'UIImageView'。這是一個可能導致崩潰的可怕假設。 – rmaddy

+0

感謝您的回答。閱讀yoir代碼,我想我必須把它放在cellForRowAtIndexPath方法中,對吧?是不是工作:( – Quetool

+0

@rmaddy所以你的主意是什麼? – Quetool