简体   繁体   中英

Black UITableViewCell DetailDisclosure accessory button?

有没有办法将默认的UITableViewCellAccessoryDetailDisclosureButton附件按钮从蓝色变成黑色?

There isn't a "standard" black one, but it's not that much work to do what you're asking.

Create (in photoshop or something similar) your own black version of the detail disclosure button. You can screen grab and colour it in if that's easier. Then add it as a resource to your project and put it inside a UIImage like so:

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

Then create a UIImageView which contains that image:

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

Finally then you can assign that to the "accessory view" for the cell you've set up already:

[cell setAccessoryView:imageView];

Hope that helps!

//EDIT - I felt like having a quick 5 mins in photoshop so created a black one for you. have fun!

removed dead ImageShack link

The answer from h4xxr didn't completely work for me in iOS 5.1.1 (clicking on the accessory view didn't call the tableView:accessoryButtonTappedForRowWithIndexPath method), so I altered his solution with help from this related answer , using a UIButton with the image rather than a UIView , which can call a custom selector if clicked:

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];

There is a much easier solution on iOS7. Use the tintColor property on UIView . Subclasses generally tend to respect it, and the disclosure indicator is no exception.

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM