ios7 uitableviewcell image left offset

后端 未结 1 1037
情书的邮戳
情书的邮戳 2021-01-11 16:37

In iOS 6 and earlier a uitableviewcell\'s imageView was positioned all the way over to the left with a 0 offset. In iOS 7 though this has been changed and there is now a 15

相关标签:
1条回答
  • 2021-01-11 17:25

    It appears I was doing it the correct way. The missing piece regarding the divider between fields was setting the inset on iOS 7. You can do this in the viewdidload or viewwillload and set self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);

    You will need to add a check if running iOS 7 or newer as this is a new property I believe. A better option might be setting it in the storyboard by selecting the table view and then setting separator insets from default to custom.

    Here is the layoutSubviews method that repositions imageView and textLabel. If you have a description add that as well.

    - (void) layoutSubviews
    {
        [super layoutSubviews];
        // Makes imageView get placed in the corner
        self.imageView.frame = CGRectMake( 0, 0, 80, 80 );
    
        // Get textlabel frame
        //self.textLabel.backgroundColor = [UIColor blackColor];
        CGRect textlabelFrame = self.textLabel.frame;
    
        // Figure out new width
        textlabelFrame.size.width = textlabelFrame.size.width + textlabelFrame.origin.x - 90;
        // Change origin to what we want
        textlabelFrame.origin.x = 90;
    
        // Assign the the new frame to textLabel
        self.textLabel.frame = textlabelFrame;
    }
    
    0 讨论(0)
提交回复
热议问题