Ios BoundingRectize在希伯来语中是错误的
我建立的这个方法在英语中非常有效。 现在我也在尝试支持希伯来语,而Ios BoundingRectize在希伯来语中是错误的,ios,nsstring,hebrew,Ios,Nsstring,Hebrew,我建立的这个方法在英语中非常有效。 现在我也在尝试支持希伯来语,而boundingrecthwithize忽略了高度(给了我一些太短的东西) 不明白为什么 + (void) setTextAndFitLabel:(UILabel *)label text:(NSString *)text { [label setNumberOfLines:0]; text = [text stringByReplacingOccurrencesOfString:@"\\n" withString
boundingrecthwithize
忽略了高度(给了我一些太短的东西)
不明白为什么
+ (void) setTextAndFitLabel:(UILabel *)label text:(NSString *)text
{
[label setNumberOfLines:0];
text = [text stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
[label setText:text];
NSDictionary *attributes = @{NSFontAttributeName: label.font};
CGRect rect = [label.text boundingRectWithSize:CGSizeMake(label.frame.size.width, CGFLOAT_MAX )
options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
attributes:attributes
context:nil];
if ([text isEqualToString:@""])
{
rect = CGRectMake(0,0,0,0);
}
CGRect labelFrame = label.frame;
labelFrame.size.height = ceil(rect.size.height);
NSArray *constraints = [label constraints];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"firstAttribute = %d", NSLayoutAttributeHeight];
NSArray *filteredArray = [constraints filteredArrayUsingPredicate:predicate];
if(filteredArray.count == 0){
label.frame = labelFrame;
}
else
{
NSLayoutConstraint *heightConstraint = [filteredArray objectAtIndex:0];
heightConstraint.constant = ceil(rect.size.height);
}
}
-boundingRectWithSize
仅计算打印文本所需的空间量。当您询问
UI/Label/TextView/Textfield
的大小时,您应该考虑到它们是具有特定属性的视图,例如,在打印文本之前,UITexView包含一些插图。在分配文本调用
-sizeToFit
或-sizeThatFits:
之后,询问其帧。我不知道您为什么需要这样做,但值得一提的是,UILabel内在内容大小是在完全显示指定文本时计算的。不幸的是,使用autolayout时,您需要这样做。但是,请留下这一点-您没有回答我的问题-为什么
boundingRectWithSize
在同一字体上以英语返回一个好的高度,而以希伯来语返回一个坏的高度…这不是真的,我在iOS7中有一个自动调整大小的表视图单元格,它使用siteToFit来获取标签的高度,并更新一个使TVC高度动态的约束。我想我确实回答了你的问题,说你没有使用正确的方法。嘿,波阿斯!你发现了吗?这让我抓狂啊三年过去了。。。不记得了。。。对不起,谢谢,我决定把我的设计改成固定大小的字体。英雄联盟