Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7537439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:51:09+00:00 2026-05-30T06:51:09+00:00

I have a UITableView, and currently it has a single cell in it. I

  • 0

I have a UITableView, and currently it has a single cell in it. I have written a custom TableViewCell class which inherits from UITableViewCell in order to do some custom drawing. I have set the width of the table to the desired size, and am trying to set the width of the cell to the same size, so it will fill up the entire width of the table. The problem seems to be that I’m getting some margins on the left and right sides of the cell, and I don’t know why.

Here’s an example of the problem.
I made the TableView background black to be more clear. The TableView is the correct size. The background image is added to the cell, not the table, and it should be taking up the full width of the table.

I have tried making the TableView wider (as wide as the screen) to try to accommodate the size of the background image, but that doesn’t quite do it. I would rather just figure out where these margins are coming from, and how I can get rid of them.

The TableView itself is initialized in Interface Builder. The style is set to Grouped, scrolling is disabled, and the view mode is set to Scale To Fill.

Here’s the cell class’ initWithStyle method

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier          
{                                                                                                    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {                        
        // Initialization code                                                                       
        _primaryLabel = [[UILabel alloc] init];                                                      
        _primaryLabel.textAlignment = UITextAlignmentLeft;                                           
        _primaryLabel.font = [UIFont systemFontOfSize:18];                                           
        _primaryLabel.backgroundColor = [UIColor clearColor];                                        
        _detailLabel = [[UILabel alloc] init];                                                       
        _detailLabel.textAlignment = UITextAlignmentLeft;                                            
        _detailLabel.font = [UIFont systemFontOfSize:12];                                            
        _detailLabel.backgroundColor = [UIColor clearColor];                                         
        _icon = [[UIImageView alloc] init];                                                          

        [self.contentView addSubview:_primaryLabel];                                                 
        [self.contentView addSubview:_detailLabel];                                                  
        [self.contentView addSubview:_icon];                                                         

        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;                            
        UIImageView* whiteDisclosureView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 15, 13)];
        [whiteDisclosureView setImage:[UIImage imageNamed:@"white_disclosure.png"]];                 
        self.accessoryView = whiteDisclosureView;

        UIImageView * background = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 305, 61)];     
        [background setImage:[UIImage imageNamed:@"button_silver.png"]];
        [self setBackgroundView:background];
        self.backgroundColor = [UIColor clearColor];                                                 

        self.frame = self.contentView.frame = CGRectMake(0, 0, 305, 61);                             
    }   
    return self;                                                                                     
}   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:51:10+00:00Added an answer on May 30, 2026 at 6:51 am

    Is your tableView using “grouped” style? With grouped style, iOS normally adds left and right margin for the table cells.

    It may be possible to remedy this by adjusting the frame of the tableView to slightly outside its superview. See here for example in previous question

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short Explanation Currently I have a UITableView which contains cells of videos from a
In my app, I have a UITableView which has some custom cells and in
I have a UITableView that displays single large images in each cell. The names
I currently have a UIScrollView which has a content size equal to about 50
I have a UITableView with a few UITableViewCell s. Each cell contains a UITextfield
I have a UITableView on a view. This UITableView has cells which are made
I have a UITableViewController which has two sections. The first section shows a single
I have a grouped uitableview which has several sections. The sections are showing up
I have a simple UITableView with two sections. Each section has a header which
I have a UITableView cell that is going to have a variable size depending

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.