2013-05-02 61 views
1

我想得出以下UIPageControl指标:使用Core Graphics绘制UIPageControl指标?

enter image description here

目前,我有下面的代码,这会导致:

enter image description here

if (isHighlighted) { 
    UIBezierPath *ovalPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 6, 6)]; 

    [[UIColor blackColor] setStroke]; 
    [ovalPath stroke]; 
    [ovalPath addClip]; 

    UIColor *lightGradientColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.0]; 
    UIColor *darkGradientColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1.0]; 

    CGFloat locations[2] = {0.0 ,1.0}; 
    CFArrayRef colors = (__bridge CFArrayRef) [NSArray arrayWithObjects:(id)lightGradientColor.CGColor, 
       (id)darkGradientColor.CGColor, 
       nil]; 
    CGColorSpaceRef colorSpc = CGColorSpaceCreateDeviceRGB(); 
    CGGradientRef gradient = CGGradientCreateWithColors(colorSpc, colors, locations); 

    CGContextDrawLinearGradient(context, gradient, CGPointMake(CGRectGetMaxX([ovalPath bounds]), 0), CGPointMake(0, CGRectGetMaxY([ovalPath bounds])), (CGGradientDrawingOptions)NULL); 

    CGColorSpaceRelease(colorSpc); 
    CGGradientRelease(gradient); 
} else { 
    UIBezierPath *ovalPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 6, 6)]; 
    [[UIColor colorWithWhite:1 alpha:0.3] setFill]; 
    [[UIColor whiteColor] setFill]; 
    [ovalPath fill]; 
} 

但我不能得到它看起来像图片中的指标。我将如何设法取得正确的结果?

+0

如果outcommneted代码不相关;不包括它。 – timss 2013-05-02 14:49:09

+0

谢谢..删除:) – 7c9d6b001a87e497d6b96fbd4c6fdf 2013-05-02 14:50:15

+0

对不起,编辑系统意外地读取了删除的注释代码,所以我不得不重新编辑它。似乎它最终修复了。 – timss 2013-05-02 14:59:01

回答

1

你试图复制的例子是确实是很小。如果您查看大型版本,您可能会发现更容易剖析 - 将模拟器设置为视网膜模式,或在Retina设备上截取屏幕截图,然后将其展开。 (也许在这里发布吧?)另外,不要先考虑代码 - 考虑你正在绘制的代码,然后担心代码执行它。

它看起来像我一样,你有:两个点可能会建立三个同心圆,半径2,3和4点。对于白色:先以深灰色(或半透明黑色)填充绘制4点半径的圆。然后,最重要的是,一个三角半径的圆和一个浅灰色的渐变填充(垂直方向,不像你有对角线)。最后,画出没有填充和1pt梯度(浅到浅灰色)笔划的内部2点半径圆。仔细看看黑圈,你可能会想出一个类似的策略来绘制它。

+0

非常感谢! :) – 7c9d6b001a87e497d6b96fbd4c6fdf 2013-05-04 07:47:07

相关问题