Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide shadows in UITableViewCell when cell is dragging

I have UITableView with hided separator line, and when I dragging cell, shadows appears some kind as borders comes out on up and down. How to hide this? Please see example: Emulator screenshot

Great thanks!

like image 734
Alexander Zakatnov Avatar asked Jan 30 '13 15:01

Alexander Zakatnov


4 Answers

So, I have answer, just subclass of UITableView with method:

- (void) didAddSubview:(UIView *)subview
{
    [super didAddSubview:subview];

    if([subview.class.description isEqualToString:@"UIShadowView"]) {
        subview.hidden = YES;
    }
}
like image 69
Alexander Zakatnov Avatar answered Nov 14 '22 23:11

Alexander Zakatnov


NoShadowTableView.m

#import "NoShadowTableView.h"

@interface NoShadowTableView ()
{
    //  iOS7
    __weak UIView* wrapperView;
}

@end

@implementation NoShadowTableView

- (void) didAddSubview:(UIView *)subview
{
    [super didAddSubview:subview];

    //  iOS7
    if(wrapperView == nil && [[[subview class] description] isEqualToString:@"UITableViewWrapperView"])
        wrapperView = subview;

    //  iOS6
    if([[[subview class] description] isEqualToString:@"UIShadowView"])
        [subview setHidden:YES];
}

- (void) layoutSubviews
{
    [super layoutSubviews];

    //  iOS7
    for(UIView* subview in wrapperView.subviews)
    {
        if([[[subview class] description] isEqualToString:@"UIShadowView"])
            [subview setHidden:YES];
    }
}

@end
like image 27
Vito Ziv Avatar answered Nov 14 '22 23:11

Vito Ziv


Quick hack is subclassing UITableViewCell and add method:

 override func layoutSubviews() {
        super.layoutSubviews()

        superview?.subviews.filter({ "\(type(of: $0))" == "UIShadowView" }).forEach { (sv: UIView) in
            sv.removeFromSuperview()
        }
    }
like image 43
FunkyKat Avatar answered Nov 14 '22 22:11

FunkyKat


This code works for me!

import UIKit

class NoShadowTableView: UITableView {

    override func didAddSubview(_ subview: UIView) {
        super.didAddSubview(subview)
        if "\(type(of: subview))" == "UIShadowView" {
            subview.removeFromSuperview()
        }
    }

}
like image 27
Rafael Gonçalves Avatar answered Nov 14 '22 22:11

Rafael Gonçalves