我有一個基本的UILabel,我在UITableViewCell
中使用。我遇到了一些奇怪的行爲,在某些單元格(並非全部)上,UILabel會得到一個灰色的頂部邊框,請參閱下面的圖片。我不確定如何解決它。UILabel在iOS7中有一個奇怪的灰色頂線/邊框,我該如何刪除它?
創建我的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;
[...]
}
您是否嘗試過設置BG顏色清除? –
@AleksanderAzizi,是的,它沒有幫助。 – Anders
您是否嘗試刪除uitableviewcell分隔符? – Ilario