gpt4 book ai didi

iphone - SQLite 的 NSArray 绘制 CGRects

转载 作者:行者123 更新时间:2023-11-29 13:45:19 25 4
gpt4 key购买 nike

我希望有人能够为我指明正确的方向。我是 iOS/Objective C 的新手,但熟悉经典的 ASP/PHP。

我正在尝试使用 SQLite 数据库中的数据动态生成 CGRect(填充的椭圆)。我能够连接到 SQLite 数据库并提取一个数组,这样就可以了。您会看到我的 CGRect 目标已成功写入 NSLog,并手动绘制了两个点。

我只需要在正确的方向上稍微插入一下,以找到将“记录集”中的项目放入 CGRect 行的最佳方法,方法与我将其发送到 NSLog 的方法类似。

我的工作 CGRect 代码:

- (void)drawRect:(CGRect)rect {

CGContextRef context = UIGraphicsGetCurrentContext();

// Set dot alpha transparency
CGContextSetAlpha(context, 0.70);

// And draw with a blue fill color
CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0);

// Fill rect convenience equivalent to AddEllipseInRect(); FillPath();
int ellipseDiameter = 35.0;
int drawOffset = ellipseDiameter / 2;

//NSArray into NSLog showing how CGRect should be formatted from SQLite data
NSArray *locationInfos = [LocationDatabase database].locationInfos;
for (LocationInfo *info in locationInfos) {
NSLog(@"CGContextFillEllipseInRect(context, CGRectMake(%@ - drawOffset, %@ - drawOffset, ellipseDiameter,ellipseDiameter))", info.xCoordText, info.yCoordText);
}

//drawing dot 1
CGContextFillEllipseInRect(context, CGRectMake(125.0 - drawOffset, 108.0 - drawOffset, ellipseDiameter, ellipseDiameter));

//drawing dot 2
CGContextFillEllipseInRect(context, CGRectMake(132.0 - drawOffset, 146.0 - drawOffset, ellipseDiameter, ellipseDiameter));
}

任何方向都将不胜感激。提前致谢!

最佳答案

info.xCoordTextinfo.yCoordText都是NSString,调用[info.xCoordText floatValue]即可将它们变成花车。

即:

CGContextFillEllipseInRect(context, CGRectMake(info.xCoordText.floatValue - drawOffset, info.yCoordText.floatValue - drawOffset, ellipseDiameter,ellipseDiameter));

关于iphone - SQLite 的 NSArray 绘制 CGRects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7680723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com