Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent table cell border to be cut by cell image?

i have a table view and i want to add image on it by using the following code,

first by overriding layoutSubviews

- (void)layoutSubviews{
    [super layoutSubviews];
self.imageView.frame = CGRectMake(15, 5, 50, 45);
self.imageView.layer.cornerRadius = 5.0f;
self.imageView.layer.masksToBounds = YES;
self.imageView.contentMode = UIViewContentModeScaleAspectFill;
}

and then using it in the -(MyTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

 NSString *imageUrlString = [userInfoResponse[indexPath.row - beginIndex] objectForKey:@"image_url"];
        NSURL * imageURL = [NSURL URLWithString:imageUrlString];
        if ( [[NSUserDefaults standardUserDefaults] objectForKey:imageUrlString] == nil ) {
            [[NSUserDefaults standardUserDefaults] setObject:[NSData dataWithContentsOfURL:imageURL] forKey:imageUrlString];
        }
        UIImage * img = [UIImage imageWithData:[[NSUserDefaults standardUserDefaults] objectForKey:imageUrlString]];
        cell.imageView.image = img;
}

and in this line i added

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 55.0;
}

it works fine with this little problem (see attached image). I don't want the cell border line to be interrupted by the image.

enter image description here

I tried playing on codes but it wont help. Anyone knows the answer? please help. Thanks

NOTE: It works well with iOS 6, this screenshot is on iOS 7. Can it be a new settings for iOS 7 UITableView?

like image 300
caribbean Avatar asked Dec 09 '22 12:12

caribbean


1 Answers

Go to your table view controller and put these codes into viewDidLoad:

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) //should check version to prevent force closed
{
    self.tableView.separatorInset = UIEdgeInsetsZero;
}
like image 125
Quang Hà Avatar answered Dec 25 '22 23:12

Quang Hà