Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell- how to change selectedBackgroundView, default ImageView, textLabel, detailTextLabel frames

I am creating tableview with row height 100, between each row i want a 5 pixels gap. For that for each row i am adding uiview(width:320px, hight:1px) at row's 95th 'y' position . Now everything is going fine. But when i select the cell the rows selectedbackgroundview covering entire row i. But i want to set rows selectedbackgroundview height as 95.

i tried following way in cellForRowAtIndexPath but no use, please help me out.

cell.selectedBackgroundView.frame = CGRectMake (0, 0, 320, 95);
like image 747
Anjaneyulu Battula Avatar asked Dec 05 '22 05:12

Anjaneyulu Battula


1 Answers

Thanks for your answer, Finally got the solution.

We can adjust the selectedBackgroundView frame by creating the custom cell. Steps to solve the problem.

  1. First we have to create class with UiTableViewCell as a Subclass
  2. Inside that under layoutSubviewsmethod we can change the tableviewcell related view frames those are selectedBackgroundView, defalut imageView, textLabel, detailTextLabel frames

    To change the selecteddBackgroundView frame

     - (void )layoutSubviews {
    // always try to set frame in layoutSubviews
    [super layoutSubviews];
    self.selectedBackgroundView.frame = CGRectMake(10, 0, self.frame.size.width - 20, 88);
     }
    

    To change the textLabel, detailTextLabel Frames

        - (void)layoutSubviews {// always try to set frame in layoutSubviews
        [super layoutSubviews];
        self.textLabel.frame = CGRectMake(0, 0, 50, 20);
        self.detailTextLabel.frame = CGRectMake(55, 0, 225, self.frame.size.height);
    
       }
    
like image 183
Anjaneyulu Battula Avatar answered May 14 '23 10:05

Anjaneyulu Battula