2

I am using UITableView with static cells to make a small form.

I added number of sections in the UITableView but now I have to remove the background color and the border of the section that displays the Login and Forgot Password button.

Check out the screenshot below.

enter image description here

Question 1

How can I remove the background color and the border?

Question 2

Also is there anyway to change the background color of the view. This view inherits from UITableViewController. I believe that I need to change the color of section or the group.

I assigned the identifier to the cell and got to remove the background color.

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{

    if([cell.reuseIdentifier isEqualToString:@"ButtonsCell"])
    {
        cell.backgroundColor = [UIColor clearColor];



        NSLog(@"login buttons cells found");
    }


}

Here is the image:

enter image description here

But the borders are still showing!


SOLUTION

Weird but works!

cell.backgroundView = nil; 
IluTov
  • 6,807
  • 6
  • 41
  • 103
azamsharp
  • 19,710
  • 36
  • 144
  • 222
  • Why dont you add those buttons inside tableview's footer view? for changing color, try to set backgroundColor property of self. – iDev Dec 24 '12 at 20:59
  • Can this be done using IB or I have to dive into code? – azamsharp Dec 24 '12 at 21:00
  • I haven't used IB, but it should be possible there. Check if you can drag and drop a UIView as table view's footer and then add buttons as its subviews. – iDev Dec 24 '12 at 21:01
  • I tried I don't think it can be done using IB. – azamsharp Dec 24 '12 at 21:02
  • 1
    @azamsharp you can add tablefooterview in interface builder itself. for that u need to add a prototype cell and create a separate view with two buttons and drag the view and drop below to the prototype cell will add that view as a footer view. then u can remove the unwanted prototype cell anyway..its easy..try it – Dinesh Raja Dec 24 '12 at 21:15
  • I got everything to work but how do I change the color of the background of the tableView. I want to change the background from vertical lines to something else. – azamsharp Dec 24 '12 at 23:48
  • You should answer your own question and mark it as correct so it get's removed from the open questions. – IluTov Dec 25 '12 at 02:18

1 Answers1

2

I think you want to do a switch cased based on your section within cellForRowAtIndexPath. Then replace the background of that row with a view that's transparent.

switch (section)
    {
        case BACKGROUND_SECTION:
        {
            // Only way I could find to get row centered
            segmentCell.selectionStyle = UITableViewCellSelectionStyleNone;
        [segmentCell setAccessoryType:UITableViewCellAccessoryNone];
            // Make the cell background transparent
            UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
            backView.backgroundColor = [UIColor clearColor];
            segmentCell.backgroundView = backView;
        }
}
DenVog
  • 4,226
  • 3
  • 43
  • 72