我一直试图让这个工作比我关心管理员的时间长得多,但我已经搜索了几乎所有的文章,而且似乎没有一个解决方案在做任何事情......
我的问题是我试图根据文本量调整标题(UILabel)的大小,在调整标题大小后,我想将图像移动到标题下方 100 像素。
图像框架显示该值已更改为计算得出的值,但应用程序从未更改,它仅显示在情节提要中进行的设计。
故事板布局:
- 看法
- 滚动视图
- 图像视图
- 标签 - 标题
- 滚动视图
下面的代码显示了一些值的打印输出,没有运行它,其中的一个示例是:
Before: [0.000000]
After: [24.000000]
Label Expected Size: 280.000000, 96.000000
After Title Assign: [96.000000]
Image Y Before: [0.000000]
Image Y After: [196.000000]
代码:
self.Title.text = NewsCell.Title;
self.Image.image = NewsCell.Image;
// fit title
printf("Before: [%f]\n", self.Title.frame.size.height);
[self.Title sizeToFit];
printf("After: [%f]\n", self.Title.frame.size.height);
//self.Title.frame = CGRectMake(20, 5, 280, self.Title.frame.size.height);
self.Title.numberOfLines = 0;
CGSize maximumLabelSize = CGSizeMake(280, 100);
CGSize expectedLabelSize = [self.Title.text sizeWithFont:self.Title.font constrainedToSize:maximumLabelSize lineBreakMode:self.Title.lineBreakMode];
self.Title.frame = CGRectMake(20,0,expectedLabelSize.width, expectedLabelSize.height);
printf("Label Expected Size: %f, %f\n", expectedLabelSize.width, expectedLabelSize.height);
printf("After Title Assign: [%f]\n", self.Title.frame.size.height);
// set image location to be bototm of title + 100
printf("Image Y Before: [%f]\n", self.Image.frame.origin.y);
double titleBottom = self.Title.frame.origin.y + self.Title.frame.size.height + 100;
self.Image.frame = CGRectMake(0, titleBottom, 320, 200);
printf("Image Y After: [%f]\n", self.Image.frame.origin.y);
// set description location
double imageBottom = self.Image.frame.size.height + self.Image.frame.origin.y + 5;
// description expand
[self.Description.text stringByAppendingString: @"\n\n © 2013 Geekosystem, LLC"];
[self.Description sizeToFit];
self.Description.frame = CGRectMake(20, imageBottom, 280, self.Description.frame.size.height);
self.Description.numberOfLines = 0;