contents
свойство работает только с CGImageRef
.Если вы хотите использовать текст на нем, используйте CATextLayer
.
Пример использования
CATextLayer * textLayer = [CATextLayer layer];
textLayer.backgroundColor = [[UIColor darkGrayColor] CGColor];
textLayer.foregroundColor = [[UIColor whiteColor] CGColor];
textLayer.bounds = CGRectMake(0, 0, 60, 40);
textLayer.position = CGPointMake(25, 25);
textLayer.string = @"Hello World";
textLayer.font = CGFontCreateWithFontName(CFSTR("Helvetica"));
textLayer.fontSize = 15.0;
[self.window.layer addSublayer:textLayer];
Конечно, я теряю память с CGFontCreateWithFontName
.Вы можете исправить это, присвоив его переменной и выпустив позже.