gpt4 book ai didi

ios - 找到UILabel的底部位置,以便可以在下面创建第二个UILabel

转载 作者:行者123 更新时间:2023-12-01 18:23:00 24 4
gpt4 key购买 nike

我正在创建一篇新文章。为文章标题添加了UILabel。标题文本有时可能是一,两或三行文本。然后,我需要在标题下方创建一个UILabel

由于标题具有动态高度,我无法定位日期UILabel

是否有计算方法可以获取UILabel框架的底部位置?

注意:我正在使用siteToFit来确保UILabel的框架适合。

// Text
UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, self.view.bounds.size.width-20, 50)];
//title.backgroundColor = [UIColor clearColor];
title.backgroundColor = [UIColor redColor];
title.text = self.firstItem.title;
//title.text = @"This is a test of a short title that is a little longer";
title.textColor = [UIColor whiteColor];
title.layer.shadowColor = [UIColor blackColor].CGColor;
title.layer.shadowOffset = CGSizeMake(0, 0);
title.layer.shadowRadius = 0.6;
title.textAlignment = NSTextAlignmentLeft;
title.layer.shadowOpacity = 1.0;
title.layer.masksToBounds = NO;
title.font = [UIFont boldSystemFontOfSize:16.0];
title.numberOfLines = 0;
[title sizeToFit];

[self.firstNewsItemBackgroundView addSubview:title];
self.cachedParalax = self.firstNewsItemBackgroundView.frame;

// Fix positioning
title.center = CGPointMake(title.center.x, self.imageView.frame.size.height - title.frame.size.height);

// Date
UILabel *titleDate = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, self.view.bounds.size.width-20, 50)];
titleDate.backgroundColor = [UIColor clearColor];
titleDate.text = self.firstItem.publishedDateString;
titleDate.textColor = [UIColor whiteColor];
titleDate.layer.shadowColor = [UIColor blackColor].CGColor;
titleDate.layer.shadowOffset = CGSizeMake(0, 0);
titleDate.layer.shadowRadius = 0.7;
titleDate.textAlignment = NSTextAlignmentLeft;
titleDate.layer.shadowOpacity = 0.95;
titleDate.layer.masksToBounds = NO;
titleDate.font = [UIFont italicSystemFontOfSize:12.0];
titleDate.numberOfLines = 0;
[title sizeToFit];
[self.firstNewsItemBackgroundView addSubview:titleDate];

// Fix positioning
CGRect frame = titleDate.frame;
titleDate.frame = CGRectMake(10, title.center.y + (title.frame.size.height/2), frame.size.width, frame.size.height);

最佳答案

好吧,看来您有错字。您正在再次调用[title sizeToFit],而不是[titleDate sizeToFit],这可能是问题的一部分。

至于使用10像素空格定位日期标签:

CGRect dateFrame = titleDate.frame;
dateFrame.origin.y = title.frame.origin.y + title.frame.size.height + 10;
[titleDate setFrame:dateFrame]

关于ios - 找到UILabel的底部位置,以便可以在下面创建第二个UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16158518/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com