gpt4 book ai didi

ios - UILabel 在 iOS7 中有一个奇怪的灰色顶线/边框,我该如何删除它?

转载 作者:IT王子 更新时间:2023-10-29 08:13:19 26 4
gpt4 key购买 nike

我有一个在 UITableViewCell 中使用的基本 UILabel。我遇到了一些奇怪的行为,在某些单元格(不是全部)上,UILabel 的顶部边框是灰色的,请参见下图。而且我不确定如何解决它。

enter image description here

我这样创建我的 UILabel:

if (self.postText == nil) {
CGRect postTextRect = CGRectMake(self.profileImage.frame.origin.x + self.profileImage.frame.size.width + 5, self.username.frame.origin.y + self.username.frame.size.height, frame.size.width - self.profileImage.frame.size.width - self.profileImage.frame.origin.y -10, self.frame.size.height - self.username.frame.size.height - self.username.frame.origin.y + 40);
self.postText = [[UILabel alloc] initWithFrame:postTextRect];
self.postText.backgroundColor = [UIColor whiteColor];
self.postText.textColor = [UIColor darkGrayColor];
self.postText.userInteractionEnabled = NO;
self.postText.numberOfLines = 0;
[self.containerView addSubview:self.postText];
}

关于如何解决这个问题有什么想法吗?

更新

我的 cellForRowAtIndexPath 看起来像这样:

- (id)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[...]
static NSString *postCellIdentifier = @"PostCell";
PostCell *cell = [tableView dequeueReusableCellWithIdentifier:postCellIdentifier];
if (cell == nil) {
cell = [[PostCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:postCellIdentifier];
}

[self configureCell:cell atIndexPath:indexPath forPost:cellPost];
return cell;
}

configureCell 的相关部分是这样的:

- (void)configureCell:(PostCell *)cell atIndexPath:(NSIndexPath *)indexPath forPost:(Post *)post
{
[...]

cell.username.text = cellUser.username;
cell.selectionStyle = UITableViewCellSelectionStyleNone;

CGSize maximumLabelSize = CGSizeMake(cell.postText.frame.size.width, FLT_MAX);
CGSize expectedLabelSize = [cell.postText.text sizeWithFont:cell.postText.font constrainedToSize:maximumLabelSize lineBreakMode:NSLineBreakByWordWrapping];
CGRect newFrame = cell.postText.frame;
newFrame.size.height = expectedLabelSize.height;
cell.postText.frame = newFrame;

CGRect containerRect = CGRectMake(5, 5, cell.containerView.frame.size.width, cell.postText.frame.size.height + cell.username.frame.origin.y + cell.username.frame.size.height + 10);
if (containerRect.size.height < 65) {
containerRect.size.height = 65;
}

cell.containerView.frame = containerRect;
[...]
}

最佳答案

我遇到了同样的问题,通过将高度四舍五入解决了这个问题:

newFrame.size.height = ceilf(expectedLabelSize.height);

关于ios - UILabel 在 iOS7 中有一个奇怪的灰色顶线/边框,我该如何删除它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21065921/

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