绘画 某种字体 以某种折行规则 最后画出的text有多大
NSString * myText = [NSString stringWithString:@"some text"];
//獲取到文本大大小
CGFloat constrainedSize = 265.0f; //其他大小也行
UIFont * myFont = [UIFont fontWithName:@"Arial" size:19]; // UILabel使用的字體
CGSize textSize = [myText sizeWithFont: myFont
?????????????????????? constrainedToSize:CGSizeMake(constrainedSize, CGFLOAT_MAX)
?????????????????????????? lineBreakMode:UILineBreakModeWordWrap];
textSize.width
textSize.height
即為UILable的寬和高,
UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];
//
UILineBreakModeWordWrap = 0,
?? 以單詞為單位換行,以單位為單位截斷。
?? UILineBreakModeCharacterWrap,
?? 以字符為單位換行,以字符為單位截斷。
?? UILineBreakModeClip,
?? 以單詞為單位換行。以字符為單位截斷。
?? UILineBreakModeHeadTruncation,
?? 以單詞為單位換行。如果是單行,則開始部分有省略號。如果是多行,則中間有省略號,省略號后面有4個字符。
?? UILineBreakModeTailTruncation,
?? 以單詞為單位換行。無論是單行還是多行,都是末尾有省略號。
?? UILineBreakModeMiddleTruncation,
?? 以單詞為單位換行。無論是單行還是多行,都是中間有省略號,省略號后面只有2個字符。
//
?
// Single line, no wrapping. Truncation based on the UILineBreakMode.
- (CGSize)sizeWithFont:(UIFont *)font; // Uses UILineBreakModeWordWrap
- (CGSize)sizeWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode;
// Single line, no wrapping. Truncation based on the UILineBreakMode.
- (CGSize)drawAtPoint:(CGPoint)point withFont:(UIFont *)font; // Uses UILineBreakModeWordWrap
- (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width withFont:(UIFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode;
// Wrapping to fit horizontal and vertical size. Text will be wrapped and truncated using the UILineBreakMode. If the height is less than a line of text, it may return
// a vertical size that is bigger than the one passed in.
// If you size your text using the constrainedToSize: methods below, you should draw the text using the drawInRect: methods using the same line break mode for consistency
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size; // Uses UILineBreakModeWordWrap
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode; // UITextAlignment is not needed to determine size
// Wrapping to fit horizontal and vertical size.
- (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font; // Uses UILineBreakModeWordWrap and UITextAlignmentLeft
- (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode; // Uses UITextAlignmentLeft
- (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment;
// These methods will behave identically to the above single line methods if the string will fit in the specified width in the specified font.
// If not, the font size will be reduced until either the string fits or the minimum font size is reached.? If the minimum font
// size is reached and the string still won't fit, the string will be truncated and drawn at the minimum font size.
// The first two methods are used together, and the actualFontSize returned in the sizeWithFont method should be passed to the drawAtPoint method.
// The last method will do the sizing calculation and drawing in one operation.
- (CGSize)sizeWithFont:(UIFont *)font minFontSize:(CGFloat)minFontSize actualFontSize:(CGFloat *)actualFontSize forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode;
- (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width withFont:(UIFont *)font fontSize:(CGFloat)fontSize lineBreakMode:(UILineBreakMode)lineBreakMode baselineAdjustment:(UIBaselineAdjustment)baselineAdjustment; // default is UIBaselineAdjustmentAlignBaselines
- (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width withFont:(UIFont *)font minFontSize:(CGFloat)minFontSize actualFontSize:(CGFloat *)actualFontSize lineBreakMode:(UILineBreakMode)lineBreakMode baselineAdjustment:(UIBaselineAdjustment)baselineAdjustment; // default is UIBaselineAdjustmentAlignBaselines
?
轉載于:https://blog.51cto.com/3426724/838541
總結
以上是生活随笔為你收集整理的绘画 某种字体 以某种折行规则 最后画出的text有多大的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: windowsXP用VNC客户端连接ce
- 下一篇: firefox无法显示验证码