I'm hoping someone will be able to point me in the right direction. I'm new to iOS/Objective C, but famil开发者_如何学Goiar with classic ASP/PHP.
I'm trying to dynamically generate CGRects (filled ellipses) using data from an SQLite database. I am able to connect to the SQLite database and pull an array, so that's working. You'll see that I have my CGRect goal successfully writing to the NSLog, along with manually drawing two dots.
I just need a little push in the right direction as far as the best method to place items from the "record set" into the CGRect line, in a similar method to how I have it sent to the NSLog.
My working CGRect code:
- (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));
}
Any direction would really be appreciated. Thanks in advance!
info.xCoordText
and info.yCoordText
are NSString
, just call [info.xCoordText floatValue]
to turn them into floats.
i.e.:
CGContextFillEllipseInRect(context, CGRectMake(info.xCoordText.floatValue - drawOffset, info.yCoordText.floatValue - drawOffset, ellipseDiameter,ellipseDiameter));
精彩评论