How to make a custom drawn UITableViewCell resize properly?

前端 未结 4 2130
孤城傲影
孤城傲影 2021-02-09 11:17

For performance reasons, I draw the strings for my UITableViewCell in a custom view that overrides its drawRect method to draw strings directly in the view rectangle using NSStr

4条回答
  •  既然无缘
    2021-02-09 11:51

    I usually just modify the x and width values (or whatever else) of whatever I want to be different when editing or not. UITableView automatically calls layoutSubviews when you begin editing, so you don't have to loop through your cells and do it yourself.

    - (void)layoutSubviews {
        [super layoutSubviews];
    
        CGFloat editingPadding = 5.0;
        self.textLabel = CGRectMake((self.editing ? self.textLabel.frame.origin.x + editingPadding : self.textLabel.frame.origin.x), self.textLabel.origin.y, (self.editing ? self.textLabel.frame.size.width - editingPadding : self.textLabel.frame.size.width), self.textLabel.frame.size.height);
    }
    

提交回复
热议问题