簡體   English   中英

黑色的UITableViewCell DetailDisclosure附件按鈕?

[英]Black UITableViewCell DetailDisclosure accessory button?

有沒有辦法將默認的UITableViewCellAccessoryDetailDisclosureButton附件按鈕從藍色變成黑色?

沒有“標准”的黑色,但是按照您的要求做的工作並不多。

創建(在photoshop或類似工具中)您自己的黑色的詳細信息披露按鈕。 您可以將屏幕抓取並為其着色,如果這樣更容易。 然后將其作為資源添加到您的項目中,並將其放入UIImage中,如下所示:

UIImage myImage = [UIImage imageNamed:@"blackbutton.png"];

然后創建一個包含該圖像的UIImageView:

UIImageView *imageView = [[UIImageView alloc] initWithImage:myImage];

最后,您可以將其分配給已經設置的單元的“附件視圖”:

[cell setAccessoryView:imageView];

希望有幫助!

//編輯-我想在photoshop中花5分鍾,所以為您創建了一個黑色的。 玩得開心!

刪除了死的ImageShack鏈接

來自h4xxr的答案在iOS 5.1.1中對我而言並不完全有效(單擊附件視圖未調用tableView:accessoryButtonTappedForRowWithIndexPath方法),因此我在此相關答案的幫助下更改了他的解決方案,將UIButton與圖片而不是UIView ,如果單擊該UIView ,可以調用自定義選擇器:

UIImage *myImage = [UIImage imageNamed:@"blackaccessorybutton.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, myImage.size.width, myImage.size.height);
[button setImage:myImage forState:UIControlStateNormal];
[button addTarget: self
           action: @selector(toggleCustomDetailDisclosureButton:)
 forControlEvents: UIControlEventTouchUpInside];
[cell setAccessoryView:button];

iOS7上有一個更簡單的解決方案。 UIView上使用tintColor屬性。 子類通常會尊重它,並且公開指標也不例外。

UIView *v = [[cell subviews] lastObject];
        v = v.subviews.count ? [v.subviews objectAtIndex:0] : nil; // v is the disclosure indicator
        if ([v respondsToSelector:@selector(setTintColor:)])
            v.tintColor = [UIColor greenColor];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM