我一直在努力让这项工作的时间比管理员更长,但我已经搜索了所有的s.o文章,而且没有任何解决方案似乎在做任何事情......
我的问题是我正在尝试根据文本量调整标题大小(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;