我知道我迟到了,但我刚刚准备了一个自定义视图,该视图绘制了一个披露视图。我很快就做了一个演示,所以它可能不是非常精确,它只是完成了工作。希望它可以帮助某人:
PZDisclosureIndicator.h
//
// Created by Pall Zoltan on 10/10/14.
// Copyright (c) 2014 pallzoltan. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface PZDisclosureIndicator : UIView
@property(nonatomic, strong) UIColor *color;
- (PZDisclosureIndicator *)initWithColor:(UIColor *)color;
@end
PZDisclosureIndicator.m:
//
// Created by Pall Zoltan on 10/10/14.
// Copyright (c) 2014 pallzoltan. All rights reserved.
//
#import "PZDisclosureIndicator.h"
@interface PZDisclosureIndicator ()
@property(nonatomic) CGFloat red;
@property(nonatomic) CGFloat green;
@property(nonatomic) CGFloat blue;
@property(nonatomic) CGFloat alpha;
@end
@implementation PZDisclosureIndicator
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, self.red, self.green, self.blue, self.alpha);
CGContextMoveToPoint(context, 4, 0);
CGContextAddLineToPoint(context, 4, 0);
CGContextAddLineToPoint(context, 16, 12);
CGContextAddLineToPoint(context, 4, 24);
CGContextAddLineToPoint(context, 0, 24 - 4);
CGContextAddLineToPoint(context, 9, 12);
CGContextAddLineToPoint(context, 0, 4);
CGContextAddLineToPoint(context, 4, 0);
CGContextFillPath(context);
}
- (PZDisclosureIndicator *)initWithColor:(UIColor *)color {
self = [super initWithFrame:CGRectMake(0, 0, 16, 24)];
self.backgroundColor = [UIColor clearColor];
self.color = color;
[self setNeedsDisplay];
return self;
}
- (void)setColor:(UIColor *)color {
_color = color;
[self.color getRed:&_red green:&_green blue:&_blue alpha:&_alpha];
[self setNeedsDisplay];
}
@end
然后在我的自定义单元格中,我这样做:
self.accessoryView = [[PZDisclosureIndicator alloc] initWithColor:SECONDARY_HIGHLIGHT_COLOR];
理论上你应该也可以在初始化后改变它的颜色,还没有尝试过。
看起来像这样:
Z.