相关疑难解决方法(0)

什么是 - [NSString sizeWithFont:forWidth:lineBreakMode:]有用吗?

在我的问题" 我如何-[NSString sizeWithFont:forWidth:lineBreakMode:]开始工作? "中,我了解到这-[NSString sizeWithFont:constrainedToSize:lineBreakMode:]实际上就是我所需要的.

-[NSString sizeWithFont:forWidth:lineBreakMode:]州的文档解释说它实际上并没有将文本包装到其他行.那我该如何使用呢?(例子会有所帮助.)

iphone cocoa-touch objective-c

38
推荐指数
2
解决办法
4万
查看次数

我如何获得 - [NSString sizeWithFont:forWidth:lineBreakMode:]工作?

我更新了我的问题" 调整UILabel(在iPhone SDK中)以适应? ",并在建议的解决方案中描述了我的问题,但没有得到答案.也许我会通过提出一个新问题来获得更好的结果......

我在以下代码后设置了一个断点:

NSString *theText = @"When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.";
CGSize …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch

21
推荐指数
2
解决办法
4万
查看次数

如果要包装的文本中有一个长字符串,sizeWithFont不会为UITextView提供正确的高度

有没有办法使用以下方法获得正确的NSString大小:

- (CGSize)sizeWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode
Run Code Online (Sandbox Code Playgroud)

不会被2或300个字符串抛出.目前,如果我尝试在这些长字符串上使用此方法,则会错误地计算它们,并且最终会在UITextView的底部显示大量空格.

我尝试过使用UILineBreakModeWordWrap和UILineBreakModeCharacterWrap.

调整大小正在进行中

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat     result = 44.0f;
    NSString*   text = nil;
    CGFloat     width = 0;
    CGFloat     tableViewWidth;
    CGRect      bounds = [UIScreen mainScreen].bounds;

    tableViewWidth = bounds.size.width;


    width = tableViewWidth - 150;       

    text = stringWithLongWords;

    if (text) {
        CGSize      textSize = { width, 20000.0f };     
        CGSize      size = [text sizeWithFont:[UIFont systemFontOfSize:10.0f] constrainedToSize:textSize lineBreakMode:UILineBreakModeWordWrap];

        size.height += 50.0f;               
        result = MAX(size.height, 44.0f+30.0f); 
    }

    return result;
}
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsstring uitextfield

15
推荐指数
3
解决办法
1万
查看次数

标签 统计

cocoa-touch ×2

iphone ×2

objective-c ×2

nsstring ×1

uitextfield ×1