krzysiek
krzysiek

Reputation: 187

Shadow under cells of grouped uitableview

i have UITableView with

Screenshot

enter image description here

And that's okay but i would like to change color of 'shadow' under cells. I think i've tried all background colors, tint colors, shadow colors etc and nothing... Can somebody help me?

Upvotes: 2

Views: 1704

Answers (2)

krzysiek
krzysiek

Reputation: 187

Ok, i found a solution. I've changed separator style to none and add shadow for each cell's layer

cell.layer.shadowColor = [[UIColor redColor] CGColor];
cell.layer.shadowOpacity = 1.0;
cell.layer.shadowRadius = 0;
cell.layer.shadowOffset = CGSizeMake(0.0, 1.0);

Upvotes: 3

Mike Z
Mike Z

Reputation: 4111

You can subclass the UITableViewCell that you are using and customize it any way you want. Then when you are implementing your tableView:cellForRowAtIndexPath: method you just set the cell to be one of your customized cells like this:

static NSString *CellIdentifier = @"ExampleCell";
MyCustomTableViewCell *cell = (MyCustomTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
  cell = [[MyCustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
 }
return cell;

Then an example of customizing the cell in your MyCustomTableViewCell.m file:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {


    self.clipsToBounds = YES;

    UIView* bgView = [[UIView alloc] init];
    bgView.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.25f];
    self.selectedBackgroundView = bgView;

    self.textLabel.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
    self.textLabel.shadowOffset = CGSizeMake(0, 2);
    self.textLabel.shadowColor = [UIColor colorWithWhite:0 alpha:0.25];

    UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 1)];
    topLine.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.25];
    [self.textLabel.superview addSubview:topLine];

    UIView *bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 200, 1)];
    bottomLine.backgroundColor = [UIColor colorWithWhite:0 alpha:0.25];
    [self.textLabel.superview addSubview:bottomLine];

  }
  return self;
}

This gives you a look like: this. Sorry for the narrow image, but I didn't have time to redo the whole thing to get a wide cell.

Upvotes: 0

Related Questions