Which is the best way to change the color/view of disclosure indicator accessory view in a table view cell in iOS?

前端 未结 12 1971
有刺的猬
有刺的猬 2020-12-04 10:26

I need to change the color of the disclosureIndicatorView accessory in a UITableViewCell. I think there are two ways to get this done, but I\'m not

12条回答
  •  隐瞒了意图╮
    2020-12-04 10:39

    As a contribution to the solution of @benzado I swiftified his code as followed:

    override func drawRect(rect: CGRect) {
    
      super.drawRect(rect)
    
      let context = UIGraphicsGetCurrentContext();
    
      let right_margin : CGFloat = 15.0
      let length : CGFloat = 4.5;
    
      // (x,y) is the tip of the arrow
      let x = CGRectGetMaxX(self.bounds) - right_margin;
      let y = CGRectGetMidY(self.bounds);
    
      CGContextMoveToPoint(context, x - length, y - length);
      CGContextAddLineToPoint(context, x, y);
      CGContextAddLineToPoint(context, x - length, y + length);
      CGContextSetLineCap(context, .Round);
      CGContextSetLineJoin(context, .Miter);
      CGContextSetLineWidth(context, 2.5);
    
      if (self.highlighted)
      {
        CGContextSetStrokeColorWithColor(context, UIColor.appColorSelected().CGColor);
      }
      else
      {
        CGContextSetStrokeColorWithColor(context, UIColor.appColor().CGColor);
      }
    
      CGContextStrokePath(context);
    }
    

    With a change of the app color a call to setNeedsDisplay() on the UITableCellView will update the color. I like to avoid the use of UIImage objects in cell views.

提交回复
热议问题