iOS - How to add display a string on a UIImageView
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();
CGContextS开发者_运维百科etFontSize(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.
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.
精彩评论