我正在尝试加载图像并向其添加一些文本。我的文本在 a 中UILabel
,我正在尝试将其添加到UIImage
. 我可以添加文本,但我似乎无法将其调整为正确的大小。我正在尝试使用该功能label.adjustsFontSizeToFitWidth = YES;
,但在大图像上,文本非常小。
-(UILabel *)xlabel{
if (!xlabel) {
xlabel = [[UILabel alloc] initWithFrame:self.setLablePosition];
xlabel.backgroundColor = [UIColor redColor];
xlabel.adjustsFontSizeToFitWidth = YES;
xlabel.lineBreakMode = UILineBreakModeWordWrap;
xlabel.numberOfLines = 0;
xlabel.textAlignment = UITextAlignmentCenter;
}
return xlabel;
}
-(UIImage *) textToImage:(UIImage *) myImage{
UIImage *watermarkedImage = nil;
UIGraphicsBeginImageContext(appDelegate.theImg.size);
[myImage drawAtPoint: CGPointZero];
[self.xlabel drawTextInRect:CGRectMake(0.0, 0.0, appDelegate.theImg.size.width, appDelegate.theImg.size.height)];
watermarkedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return watermarkedImage;
}
谢谢你