prabakaran iOS
prabakaran iOS

Reputation: 681

How to change Accessory type -> Disclosure Indicator color in my cell?

I can't change the default Accessory Type->Disclosure Indicator view's color in my UItableviewCell.

When I change tableviewcell tint color, it changes the following Accessory Type view color.

But I can't change the "Disclosure Indicator" color.

Do you have any other option to change 'Disclosure Indicator' color other than to set image in accessory view?

Screenshots:

Cell:
cell

Xcode menu:
xcodemenu

Upvotes: 3

Views: 4716

Answers (2)

Vivek
Vivek

Reputation: 5213

You can put your image in accessoryView and your problem solved.

Sample Code Put this code in cellForRowAtIndexPath

UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 11, 22, 22)];
imgView.contentMode = UIViewContentModeScaleAspectFit;
imgView.image = [UIImage imageNamed:@"IconMore"];
cell.accessoryView = imgView;

enter image description here

Upvotes: 2

PPL
PPL

Reputation: 6555

Apple does not provide any option for this, you can do by creating custom UIView. Please find below custom View for the same,

import UIKit

class CustomDisclosureIndicator: UIView {
    @IBInspectable
    public var color: UIColor = UIColor.darkGray {
        didSet {
            setNeedsDisplay()
        }
    }

    override func draw(_ rect: CGRect) {
        let context = UIGraphicsGetCurrentContext()

        let x = self.bounds.maxX - 3
        let y = self.bounds.midY
        let R = CGFloat(4.5)

        context?.move(to: CGPoint(x: x-R, y: y-R))
        context?.addLine(to: CGPoint(x: x, y: y))
        context?.addLine(to: CGPoint(x: x-R, y: y+R))
        context?.setLineCap(.square)
        context?.setLineJoin(.miter)
        context?.setLineWidth(2)
        color.setStroke()
        context?.strokePath()
    }
}

You can do following way,

enter image description here

Above code produces following output.

enter image description here

Try it once and let me know if any other queries are there.

Upvotes: 0

Related Questions