我想画一块电池来显示我的一个通过蓝牙连接到手机的设备的电池电量。
我如何才能做到这一点?我是个二维画的菜鸟....任何指针都是有帮助的
谢谢,
发布于 2012-12-14 03:29:46
我想画一块电池来显示我的一个通过蓝牙连接到手机的设备的电池电量。
编写代码来绘制像电池一样的无缩放的静态图像似乎很麻烦。当然,你可以这样做,但只需在绘图程序中绘制图像并将其作为资源添加到您的应用程序中要容易得多。
如果要在代码中绘制电池,请先在纸上或绘图程序中绘制形状。然后写下你需要做的所有绘图操作的列表--对于电池来说,它可能只是一系列的直线和曲线。UIBezierPath提供了这些操作,从这些操作开始可能比深入研究Quartz2D更容易。
发布于 2012-12-14 03:55:16
我用绘图程序做了这两件事,并进行了编程。今天,我发现编程更容易,更有趣,也是未来的证明:
你不必为ios分辨率的任何变化提供两张或多少张图片。
绘图中的一个技巧(不是很秘密)是,在0和1之间对绘图进行归一化,这样你就可以独立于电池大小了。您可以使用CGAffineTransformMakeScale()来实现这一点。但是,您应该更改线宽以适应缩放率:
如果按因子r进行缩放:
lineWidth必须是origLineWidth / r;//这花了我一些时间才弄清楚!
其中例如origLineWidth = 1.0;
然后你可以画:
用于电池主体的
那真是一件很好的作品。
发布于 2012-12-14 04:02:10
这是我在PaintCode中画的一个小东西,可能有点小。
CGFloat factor = 0.2; // Something between 0.0 - 1.0
//// Rectangle Drawing
UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(0.5, 0.5, 15, 5)];
[[UIColor blackColor] setStroke];
rectanglePath.lineWidth = 1;
[rectanglePath stroke];
//// Rectangle 2 Drawing -- THIS IS THE INNER "LEVEL" PART
UIBezierPath* rectangle2Path = [UIBezierPath bezierPathWithRect: CGRectMake(2, 2, 12*factor, 2)];
[[UIColor blackColor] setFill];
[rectangle2Path fill];
[[UIColor blackColor] setStroke];
rectangle2Path.lineWidth = 1;
[rectangle2Path stroke];
//// Bezier Drawing
UIBezierPath* bezierPath = [UIBezierPath bezierPath];
[bezierPath moveToPoint: CGPointMake(15.52, 1.5)];
[bezierPath addCurveToPoint: CGPointMake(17.04, 2.97) controlPoint1: CGPointMake(16.64, 1.49) controlPoint2: CGPointMake(17.05, 1.76)];
[bezierPath addCurveToPoint: CGPointMake(15.52, 4.5) controlPoint1: CGPointMake(17.02, 4.16) controlPoint2: CGPointMake(17.05, 4.48)];
[bezierPath addCurveToPoint: CGPointMake(15.52, 1.5) controlPoint1: CGPointMake(15.55, 4.48) controlPoint2: CGPointMake(15.47, 1.49)];
[bezierPath closePath];
[[UIColor blackColor] setFill];
[bezierPath fill];https://stackoverflow.com/questions/13866961
复制相似问题