RectFrame (幅 = 170、高さ = 30) にテキスト (テキストは "0%"、フォント サイズ = 30) を描画する方法を以下に示します。
/* Draw String IOS 7 up */
-(void) drawString: (CGRect) contextRect withStr: (NSString *) string {
NSMutableParagraphStyle *textStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
textStyle.lineBreakMode = NSLineBreakByWordWrapping;
textStyle.alignment = NSTextAlignmentCenter;
UIFont *font = [UIFont systemFontOfSize:_textSize];
UIColor* textColor = [UIColor grayColor];
NSDictionary* stringAttrs = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:textStyle, NSForegroundColorAttributeName:textColor};
[string drawInRect:contextRect withAttributes:stringAttrs];
}
画像の結果を投稿することはできませんが、その結果、フレームの上部から数ピクセル下にテキストが描画されますが、下部は問題ありません (テキストの下部は下部のフレームと一致します)。フレームの両方のサイズをどのように調整してもおよびテキストは、常にフレーム上部の下の「どこかに」描画されますが、何かアイデアはありますか?