2 wssg253 wssg253 于 2016.03.19 10:59 提问

Kxmenu怎么修改背景色。iOS
ios

绘制代码如下

    CGFloat R0 = 0.267, G0 = 0.303, B0 = 0.335;
CGFloat R1 = 0.040, G1 = 0.040, B1 = 0.040;

UIColor *tintColor = [KxMenu tintColor];
if (tintColor) {

    CGFloat a;
    [tintColor getRed:&R0 green:&G0 blue:&B0 alpha:&a];
}

CGFloat X0 = frame.origin.x;
CGFloat X1 = frame.origin.x + frame.size.width;
CGFloat Y0 = frame.origin.y;
CGFloat Y1 = frame.origin.y + frame.size.height;

// render arrow

UIBezierPath *arrowPath = [UIBezierPath bezierPath];

// fix the issue with gap of arrow's base if on the edge
const CGFloat kEmbedFix = 3.f;

if (_arrowDirection == KxMenuViewArrowDirectionUp) {

    const CGFloat arrowXM = _arrowPosition;
    const CGFloat arrowX0 = arrowXM - kArrowSize;
    const CGFloat arrowX1 = arrowXM + kArrowSize;
    const CGFloat arrowY0 = Y0;
    const CGFloat arrowY1 = Y0 + kArrowSize + kEmbedFix;

    [arrowPath moveToPoint:    (CGPoint){arrowXM, arrowY0}];
    [arrowPath addLineToPoint: (CGPoint){arrowX1, arrowY1}];
    [arrowPath addLineToPoint: (CGPoint){arrowX0, arrowY1}];
    [arrowPath addLineToPoint: (CGPoint){arrowXM, arrowY0}];

    [[UIColor colorWithRed:R0 green:G0 blue:B0 alpha:1] set];
    Y0 += kArrowSize;

} else if (_arrowDirection == KxMenuViewArrowDirectionDown) {

    const CGFloat arrowXM = _arrowPosition;
    const CGFloat arrowX0 = arrowXM - kArrowSize;
    const CGFloat arrowX1 = arrowXM + kArrowSize;
    const CGFloat arrowY0 = Y1 - kArrowSize - kEmbedFix;
    const CGFloat arrowY1 = Y1;

    [arrowPath moveToPoint:    (CGPoint){arrowXM, arrowY1}];
    [arrowPath addLineToPoint: (CGPoint){arrowX1, arrowY0}];
    [arrowPath addLineToPoint: (CGPoint){arrowX0, arrowY0}];
    [arrowPath addLineToPoint: (CGPoint){arrowXM, arrowY1}];

    [[UIColor colorWithRed:R1 green:G1 blue:B1 alpha:1] set];

    Y1 -= kArrowSize;

} else if (_arrowDirection == KxMenuViewArrowDirectionLeft) {

    const CGFloat arrowYM = _arrowPosition;        
    const CGFloat arrowX0 = X0;
    const CGFloat arrowX1 = X0 + kArrowSize + kEmbedFix;
    const CGFloat arrowY0 = arrowYM - kArrowSize;;
    const CGFloat arrowY1 = arrowYM + kArrowSize;

    [arrowPath moveToPoint:    (CGPoint){arrowX0, arrowYM}];
    [arrowPath addLineToPoint: (CGPoint){arrowX1, arrowY0}];
    [arrowPath addLineToPoint: (CGPoint){arrowX1, arrowY1}];
    [arrowPath addLineToPoint: (CGPoint){arrowX0, arrowYM}];

    [[UIColor colorWithRed:R0 green:G0 blue:B0 alpha:1] set];

    X0 += kArrowSize;

} else if (_arrowDirection == KxMenuViewArrowDirectionRight) {

    const CGFloat arrowYM = _arrowPosition;        
    const CGFloat arrowX0 = X1;
    const CGFloat arrowX1 = X1 - kArrowSize - kEmbedFix;
    const CGFloat arrowY0 = arrowYM - kArrowSize;;
    const CGFloat arrowY1 = arrowYM + kArrowSize;

    [arrowPath moveToPoint:    (CGPoint){arrowX0, arrowYM}];
    [arrowPath addLineToPoint: (CGPoint){arrowX1, arrowY0}];
    [arrowPath addLineToPoint: (CGPoint){arrowX1, arrowY1}];
    [arrowPath addLineToPoint: (CGPoint){arrowX0, arrowYM}];

    [[UIColor colorWithRed:R1 green:G1 blue:B1 alpha:1] set];

    X1 -= kArrowSize;
}

[arrowPath fill];

// render body

const CGRect bodyFrame = {X0, Y0, X1 - X0, Y1 - Y0};

UIBezierPath *borderPath = [UIBezierPath bezierPathWithRoundedRect:bodyFrame
                                                      cornerRadius:8];

const CGFloat locations[] = {0, 1};
const CGFloat components[] = {
    R0, G0, B0, 1,
    R1, G1, B1, 1,
};

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace,
                                                             components,
                                                             locations,
                                                             sizeof(locations)/sizeof(locations[0]));
CGColorSpaceRelease(colorSpace);


[borderPath addClip];

CGPoint start, end;

if (_arrowDirection == KxMenuViewArrowDirectionLeft ||
    _arrowDirection == KxMenuViewArrowDirectionRight) {

    start = (CGPoint){X0, Y0};
    end = (CGPoint){X1, Y0};

} else {

    start = (CGPoint){X0, Y0};
    end = (CGPoint){X0, Y1};
}

CGContextDrawLinearGradient(context, gradient, start, end, 0);

CGGradientRelease(gradient);    

2个回答

redhjb
redhjb   2016.03.19 15:09

[tintColor getRed:&R0 green:&G0 blue:&B0 alpha:&a];

r 后面的数字改一下g 也是b 也是。不知道数值,装个photoshop看一下

u014116643
u014116643   2016.03.22 14:36

CGFloat R0 = 0.267, G0 = 0.303, B0 = 0.335;
CGFloat R1 = 0.040, G1 = 0.040, B1 = 0.040;

这是颜色的RGB值,都是0~1。改变他们值就是了。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!