views:

33

answers:

1

How can I show a string on a UIImage View?

Ok Ive got this currently:

- (void)viewDidLoad {
  [super viewDidLoad];
  playerPositions = [[NSArray alloc] initWithObjects:box1,box2,box3,box4,nil];
  [box3 drawRect:box3.frame];
}

- (void)drawRect:(CGRect)rect {
  [super drawRect:rect];

  CGContextRef context = UIGraphicsGetCurrentContext();
  CGContextSetFontSize(context, 11.5);

  CGContextSelectFont(context, "Helvetica", 10.5, kCGEncodingMacRoman);
  CGContextShowText(context, "Tys", 5);
  CGContextShowTextAtPoint(context, 50, 60, "value", 5);
}

But no text shows when I test it.

A: 

I'd override UIImageView's drawRect: method:

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFontSize(context, 11.5)

    CGContextSelectFont(context, "Helvetica", 10.5, kCGEncodingMacRoman)
    CGContextShowText(context, "value", 5)
    CGContextShowTextAtPoint(context, 50, 60, "value", 5)
}

Updated:

Yesterday I faced with the same problem. Ended up with [NSString drawAtPoint:withFont] method - it works perfectly.

kovpas
I can't easily paste code in these comments, so Ive edited it into the question. Now I have this code, how do I effectivly call it? Hasn't work for me yet, see above. Where am I going wrong?
Evolve
@Evolve: see updated answer.
kovpas