0

I built a custom tableview with xib file. I added a UILabel with top border, code for top border is

UIView *topBorder = [UIView new];
topBorder.backgroundColor = [UIColor blackColor];
topBorder.frame = CGRectMake(0, 0, cell.nameOfImage.frame.size.width, 1);
[cell.nameOfImage addSubview:topBorder];

cell.nameOfImage.text = [tableData objectAtIndex:indexPath.row];

Auto resize is enter image description here

But its not resizing with screen differ as in 5s and 6s plus. It is not showing with UILabel size. In 5s

enter image description here

And in 6s Plus enter image description here

The top border is not showing with respect to label.

Pushkraj Lanjekar
  • 2,254
  • 1
  • 21
  • 34
Udai kumar
  • 233
  • 2
  • 17

1 Answers1

0

You need to update width of topBorder according cell.nameOfImage width. Move your code for frame changing to layoutSubviews:

Objective-C:

- (void)layoutSubviews {
    [super layoutSubviews];
    UIView *top = [[UIView alloc] init];
    topBorder.frame = CGRectMake(0.0, 0.0, nameOfImage.frame.size.width, 1.0)
}

Swift:

override func layoutSubviews() {
        super.layoutSubviews()
        topBorder.frame = CGRectMake(0, 0, nameOfImage.frame.size.width, 1);
    }
Artem Novichkov
  • 2,356
  • 2
  • 24
  • 34