如何使 Autoresize 属性在 Xcode 4.3 中工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9344197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make Autoresize property work in Xcode 4.3?
提问by Charles Burgess
I recently updated to Xcode 4.3 and it disabled my UILabels' autoshrink property. I rechecked the boxes in IB and rebuilt the project but it is still cutting off the text. Any suggestions? Is this a known bug? Is there a way to fix this programatically.
我最近更新到 Xcode 4.3,它禁用了我的 UILabels 的自动收缩属性。我重新检查了 IB 中的框并重建了项目,但它仍然切断了文本。有什么建议?这是一个已知的错误?有没有办法以编程方式解决这个问题。
回答by JLundell
I'm seeing the same thing. You can work around it programmatically (I do it in viewDidLoad):
我看到了同样的事情。您可以以编程方式解决它(我在 viewDidLoad 中这样做):
myLabel.adjustsFontSizeToFitWidth = YES;
回答by Andrew Smith
I had the same problem. Here's the fix, I added it to a utility method, since I have over 100 xibs in my project, and a bunch of them needed fixing. Works great.
我有同样的问题。这是修复程序,我将它添加到一个实用程序方法中,因为我的项目中有 100 多个 xib,其中很多需要修复。效果很好。
Add this to Utility.m:
将此添加到 Utility.m:
// UIView+viewRecursion.h
@interface UIView (viewRecursion)
- (NSMutableArray*) allSubViews;
@end
// UIView+viewRecursion.m
@implementation UIView (viewRecursion)
- (NSMutableArray*)allSubViews
{
NSMutableArray *arr=[[NSMutableArray alloc] init];
[arr addObject:self];
for (UIView *subview in self.subviews)
{
[arr addObjectsFromArray:(NSArray*)[subview allSubViews]];
}
return arr;
}
@end
And this:
和这个:
+(void)fixLabels:(UIView *)theView{
for(UIView *v in [theView allSubViews])
{
if([v isKindOfClass:[UILabel class]])
{
if( !((UILabel*)v).adjustsFontSizeToFitWidth ){
((UILabel*)v).adjustsFontSizeToFitWidth=YES;
// NSLog(@"fixed %@", theView);
}
}
}
}
And then call fixLabels from viewDidLoad for any view that has UILabels that are not auto shrinking:
然后从 viewDidLoad 调用 fixLabels 为任何具有不自动收缩的 UILabels 的视图:
[Utility fixLabels:self.view];
回答by Adobels
Xcode 4.3 doesn't respecting the Interface Builder Settings for adjustsFontSizeToFitWidth property.
Xcode 4.3 不考虑 adjustsFontSizeToFitWidth 属性的界面生成器设置。
You can fix it by setting the property value programmatically as JLundell suggested.
您可以按照 JLundell 的建议,通过以编程方式设置属性值来修复它。
myLabel.adjustsFontSizeToFitWidth = YES;
It has been fixed up in 4.3.1
它已在 4.3.1 中修复
回答by Dave
I have the exact opposite problem! I updated to Xcode 4.3, and now it auto shrinks the text in my tableview cells when I want them to truncate them with the ellipses. I went through the storyboard and modified all of the options that might have to do with that, but it refuses to do what I want. So frustrating.
我有完全相反的问题!我更新到 Xcode 4.3,现在当我希望它们用省略号截断它们时,它会自动缩小我的 tableview 单元格中的文本。我浏览了故事板并修改了所有可能与之相关的选项,但它拒绝做我想做的事。太令人沮丧了。
Edited...
已编辑...
Try and re-create what Xcode was doing to me since it's the reverse of what's happening to you. Highlight the prototype cell you have for your tableview in the storyboard and click on the "Title" and "Subtitle" words. You can find the AutoShrinking property within the attributes inspector, and I suppose you can fix your issue by unchecking this box and rebuilding your app. Very strange how the Xcode upgrade would cause this. It also caused my app to behave a bit strangely (i.e. crashing unexpectedly while running in the simulator), but a few clean and rebuilds solved this. Hopefully you are able to fix this, since I know it was just as frustrating for me!
尝试重新创建 Xcode 对我所做的事情,因为它与发生在你身上的事情相反。突出显示故事板中 tableview 的原型单元格,然后单击“标题”和“副标题”字样。您可以在属性检查器中找到 AutoShrinking 属性,我想您可以通过取消选中此框并重建您的应用程序来解决您的问题。非常奇怪 Xcode 升级如何导致这种情况。它还导致我的应用程序表现得有点奇怪(即在模拟器中运行时意外崩溃),但一些清理和重建解决了这个问题。希望你能解决这个问题,因为我知道这对我来说同样令人沮丧!
回答by Ron
It just did the same thing to me. All the autoshrink are turned off. Putting back a font size and turning auto shrink on didn't actually work.
它对我做了同样的事情。所有的自动收缩都关闭了。放回字体大小并打开自动缩小实际上不起作用。
I had to fix it programmatically as JLundell suggested.
我不得不按照 JLundell 的建议以编程方式修复它。