0
我有一個UILabel
用戶編輯並最終在圖像上繪製的屬性字符串。每當用戶更改UITextview
中的文字並確認時,我都會更新UILabel
。AttributedString有時不能成功繪製使用drawInRect
- (void)displayPicture {
[self.view endEditing:YES];
self.attributedStr = [[NSAttributedString alloc] initWithString:self.textInputField.text attributes:self.attributes];
self.displayField.attributedText = [[NSAttributedString alloc] initWithString:self.textInputField.text attributes:self.attributes];
self.displayField.lineBreakMode = NSLineBreakByCharWrapping;
[self.displayField sizeToFit];
[self.displayField setNeedsDisplay];
self.textInputField.hidden = YES;
self.tapRecog.enabled = YES;
self.displayField.hidden = NO;
}
現在,UILabel
顯示屏幕上所需的方式。
當用戶想要在PIC +文本組合成的UIImage並張貼,下面的代碼被實現:
- (UIImage *)generatePicture {
UIGraphicsBeginImageContextWithOptions(CGSizeMake(Picture_Standard_Width, Picutre_Standard_Height), YES, 0.0f);
[self.bgImageView.image drawInRect:CGRectMake(0, 0, Picture_Standard_Width, Picutre_Standard_Height)];
CGRect originalFrame = self.displayField.frame;
CGRect adjustedFrame = CGRectMake(originalFrame.origin.x, originalFrame.origin.y - self.bgImageView.frame.origin.y, originalFrame.size.width, originalFrame.size.height);
[self.displayField.attributedText drawInRect:adjustedFrame];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
self.imageToUpload = newImage;
UIGraphicsEndImageContext();
return self.imageToUpload;
}
大部分歸因時代的僅示出了所產生的圖像中的一行或兩行。這很可能與框架有關。我簡單地被屬性字符串很好地顯示在標籤中,而當我繪製它時會有所不同。
正確繪製屬性字符串的任何幫助將不勝感激。