0

UILabelユーザーが編集し、最終的に画像に描画する属性付きの文字列があります。UILabelユーザーがテキストを変更するたびに更新してUITextview確認する方法は次のとおりです。

 - (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+Text を 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;
}

ほとんどの場合、属性は生成された画像に 1 つまたは 2 つの行しか示しません。フレームに関係がある可能性が非常に高いです。属性付きの文字列がラベルにうまく表示され、描画すると異なるという事実に単純に混乱しています。

attributedString を正しく描画するための助けをいただければ幸いです。

4

1 に答える 1

0

絵を描き始めると、絵を描く新しい文脈が始まります。

Context は画像で、0,0 は画像コーナーです。

したがって、originalFrame を調整して、ビューのコンテキストではなく画像のコンテキストに描画していることを考慮に入れる必要があります

于 2014-01-25T11:26:28.203 に答える