开发者

iOS - How to add display a string on a UIImageView

开发者 https://www.devze.com 2023-01-20 09:16 出处:网络
How can I show a string on a UIImage View? Ok Ive got this currently: - (void)viewDidLoad { [super viewDidLoad];

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消