Posts

Post not yet marked as solved
3 Replies
Sorry man, I forgot the details1. ContextI'm trying to render a UILabel's layer using - (void)drawInContext:(CGContextRef)ctx;and the properties of the label (such as textColor、attributedText) may be changed under some circumstances.2. EnvironmentsXcode 10.2.1iOS 12.1.23. Simplified Code UILabel *someLabel = [[UILabel alloc] init]; // setting attributes someLabel.text = @"hello, world"; CGSize size = CGSizeMake(50, 20); someLabel.frame = CGRectMake(0, 0, size.width, size.height); someLabel.textColor = [UIColor whiteColor]; // textColor may be modified in other scenarios someLabel.attributedText = .... // attributedText may be modified in other scenarios UIGraphicsBeginImageContextWithOptions(size, 0, 0); CGContextRef context = UIGraphicsGetCurrentContext(); [someLabel.layer drawInContext:context]; // crashed here UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();