数字が入った円を描いてみます。
-(void)drawRect:(CGRect)rect {
//Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 4.0);
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextBeginPath(context);
CGContextAddEllipseInRect(context, rect);
CGContextDrawPath(context, kCGPathFillStroke);
// Label and index code
UILabel* circleLabel = [[UILabel alloc] init];
NSString *i=[Index stringValue];
[circleLabel setText:i];
[self addSubview:circleLabel];
}
自分のメソッドからdrawRectメソッドを呼び出します。
-(void)addPhotoIndex:(NSNumber*)tempNumber withCoordinate:(NSString*)currentTouchPos{
self.coord= CGPointFromString(currentTouchPos);
CGRect rect= CGRectMake ((coord.x - 5), (coord.y- 5), 5, 5);
NSNumber *Index= tempNumber;
[self drawRect:rect];
}
それ自体がViewControllerから呼び出されること。
しかし、これは何も描画しておらず、エラーも発生していません。誰か助けてくれませんか?
解決:
最後に、これはそれが機能したものです:
-(void)addPhotoIndex:(NSNumber*)tempNumber withCoordinate:(NSString*)currentTouchPos{
self.coord= CGPointFromString(currentTouchPos);
CGRect rect= CGRectMake ((coord.x - 3), (coord.y- 3), 3, 3);
NSNumber *Index= tempNumber;
NSString *i=[Index stringValue];
UIFont *font = [UIFont systemFontOfSize:15.0];
// Drawing Point
UIGraphicsBeginImageContext(self.frame.size);
[self.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 3.0);
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextBeginPath(context);
CGContextAddEllipseInRect(context, rect);
CGContextDrawPath(context, kCGPathFillStroke);
[ i drawAtPoint:self.coord withFont:font];
self.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
インデックス番号の付いたポイントが正しい位置に並べて描画されます:)お役に立ててありがとうございます。