日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

绘画 某种字体 以某种折行规则 最后画出的text有多大

發布時間:2024/4/15 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 绘画 某种字体 以某种折行规则 最后画出的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的寬和高,


CGRect labelFrame = CGRectMake (0, 0, textSize.width, textSize.height);
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有多大的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。