- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在将我的应用程序更新到iOS 7,终于得到了它,但是有一件事我找不到解决方案。
在Xcode 4中,我使用了以下方法:
#define FONT_SIZE 14.0f
#define CELL_CONTENT_WIDTH 280.0f
#define CELL_CONTENT_MARGIN 10.0f
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; {
NSString *text = [textA objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
CGFloat height = MAX(size.height, 28.0f);
return height + (CELL_CONTENT_MARGIN * 2);
}
Use -boundingRectWithSize:options:attributes:context:
最佳答案
在iOS7中不推荐使用 sizeWithFont 方法。您应该改为使用 boundingRectWithSize 。如果您还需要支持以前的iOS版本,则可以使用以下代码:
CGSize size = CGSizeZero;
if ([label.text respondsToSelector: @selector(boundingRectWithSize:options:attributes:context:)] == YES) {
size = [label.text boundingRectWithSize: constrainedSize options: NSStringDrawingUsesLineFragmentOrigin
attributes: @{ NSFontAttributeName: label.font } context: nil].size;
} else {
size = [label.text sizeWithFont: label.font constrainedToSize: constrainedSize lineBreakMode: UILineBreakModeWordWrap];
}
关于uitableview - sizeWithFont :constrainedToSize:lineBreakMode: deprecated in iOS7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18834275/
这个问题在这里已经有了答案: Replacement for deprecated -sizeWithFont:constrainedToSize:lineBreakMode: in iOS 7?
我有自己的从 StyledMultilineElement 派生的自定义元素: public class SubmenuElement : StyledMultilineElement { p
有没有办法在 UILabel 中的特定字符处打断文本,比如“;” ?? 我不希望它被 Word Wrap 或 character Wrap 破坏。 最佳答案 当然,只需替换所有出现的“;”在显示字符串
为什么这行不通?无论字符串的长度如何,它总是返回 18。有 this thread ,但不是确定的答案。 NSString * t = @""; CGSize size = [t si
我一直使用的许多方法来确定用于创建复杂 pdf 文档的打印字符串的布局在 iOS7 中已被弃用。文档调用了相同的方法来替代所有已弃用的 sizeWithFont 方法: boundingRectWit
我在sizeWithFont(特别是lineBreakMode)上遇到了一些麻烦。 CGSize maxSize = CGSizeMake(30, 999); UIFont *font = [UIFo
我正在 iPhone 上制作聊天应用程序。我对 sizeWithFont:constrainedToSize:lineBreakMode 函数有疑问。当 NSString 有 long length
尝试创建 CGSize 来设置 UILabel 的正确高度时出现泄漏。在 heightForRowAtIndexPath 中设置高度时,我也收到相同的泄漏。 这是泄漏的代码片段: CGSize siz
我有以下代码: float height = [string sizeWithFont:[UIFont systemFontOfSize:kFontSize] constrainedToSize:CG
sizeWithFont:constrainedToSize:lineBreakMode: 似乎没有返回正确的宽度。执行这些代码后,我看到标签中的部分字符串被截断了,这意味着我必须手动添加几个像素的大
我正在将我的应用程序更新到iOS 7,终于得到了它,但是有一件事我找不到解决方案。 在Xcode 4中,我使用了以下方法: #define FONT_SIZE 14.0f #define CELL_C
我有一个 TextView ,我想将它配置为包装不适合的第一个字符。在 UIKit 中,这相当于设置 label.lineBreakMode = .byCharWrapping .这是否已经为 Swi
在 Xamarin Forms 项目(C# 代码,而不是 XAML)中,我有一些嵌套的水平堆栈布局,如下所示: 请注意,有一个“拒绝:”标签,然后是数量标签 (4),然后是原因代码标签(“无法找到”)
如果我在 TTTAttributedLabel 示例应用“Espresso”中将 linebreakmode 设置为 truncation tail超过 3 行。行数设置为零。我错过了什么?在我注意到
在 Xcode 5 上将项目从 iOS5.0 转换为 iOS7/iOS6。下面的代码给出了编译时警告: 'sizeWithFont:constrainedToSize:lineBreakMode:'已
Shark 向我展示了这种方法对性能造成的巨大影响。就像我的表格 View 中的 80% 一样。我所做的就是为每个单元格绘制两个标签(每页总共大约 8 个)。滚动期间。我用它绘制了矩形。 有没有更好的
我正在尝试制作一个 UITableViewCell,根据它显示的字符串的长度来调整其高度,但我对此方法很感兴趣。 这是我得到的: NSString *text = @"A really long st
这个问题在这里已经有了答案: How to calculate actual font point size in iOS 7 (not the bounding rectangle)? (8 个答
当我运行以下代码时(iOS 6.1 SDK): UIFont *font = [UIFont fontWithName:@"Avenir" size:12.0]; NSString *text1 =
我正在从事一个必须同时支持 iOS6 和 iOS7 的项目。我的问题是它在不同系统上的工作方式不同。我正在尝试创建行数等于 2 的 UILabel,但是当我将它的换行模式设置为 NSLineBreak
我是一名优秀的程序员,十分优秀!