wssg253 2016-03-19 02:59 采纳率: 12.5%
浏览 1673

Kxmenu怎么修改背景色。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 2016-03-19 07:09
    关注

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

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

    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler