I have a tableview in my iPhone project. Each cell of the row is customized with a separate UITableViewCell.
The custom cell contains an imageview and a label. My row height is 55 and hence my custom table height is also 55. Imageview lies as a background for the cell, so imageview height is also 55. But when i run the project i could see a border around each row, which seems the custom cell is having a rectangular border around its contents.
How could i be able to remove this bounding rectangle. i am working in xcode 4.2.1 and simulator 5.0.
its possible that the border you see is the seperator, try to add this line to your code
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
Is it the cell separator?
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
You need to set the background view of cell-
cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
actually it was due to the image i loaded.. it had a shadow part, which appeared as the white space.. sorry for the trouble. THANK YOU ALL
Related
I have made a subclass for UITableViewCell and I am implementing Subtitle TableViewCell with a thumbnail image.
Following are the UITableViewCell contents:
The issue I am facing is when the data loads in TableViewCell, the subtitleLabel text gets hidden upto the height of the imageView. But when I select any Cell, it shows subtitleLabelText completely.
I have added the screenshot of the same for complete reference:
The UIImageView has frame = CGRectMake(0,0,40,40);
Try to give a clearColor background color for the cell title label -
cell.textLabel.backgroundColor = [UIColor clearColor];
It turns out I was using TableViewCell style as subtitle instead of custom. The style settings in subtitle was making the other labels to hide below them. What a silly miss!
In your nib or storyboard file, make sure that the label is below the image view in the list of subview components (it is in the left of the screen). The first subview in that list will be at the lowest level (behind every other subview, if they overlap).
write one line of code
Titlelabel.backgroundcolor = [UIColor ClearColor];
because your label has white background..and Titlelabel height is too large so label is colliding.
Let me know working or not!!!
Happy Coding!!!
What is the frame of Title Label? if its height is more, then also it may possible that it hides your subtitle Label
Here's a great tutorial which helped me when I was trying to do something like you want :
http://www.appcoda.com/ios-programming-customize-uitableview-storyboard/
You can adapt the size of the different components (ImageView, TitleLabel, Subtitle,...)
Hi I face the strange problem.
I have created UITableView for iPad.
When I check the cell width i found it's 320 but for iPad i need 768 and 1024.
The below screen shows the TableView in which the cell shows in Table
When I add scrollBar with following UIScrollView *previewScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, cell.contentView.frame.size.width, 250)];
NSLog(#"cell.contentView.frame.size.widt %f",cell.contentView.frame.size.width);
the scrollbar shows only 320 width(cell.contentView.frame.size.width) area.
what should i do for set the iPad size cell content view
You should use autoResizingFlags correctly. On creation, the cell is only 320px width, but on display it will be larger.
Try this, when creating your scrollview:
previewScrollView.autoresizingFlags = UIViewAutoresizingFlexibleWidth;
This should work, but when you even need more control, you can still use the tableView delegate method: tableView:willDisplayCell:atIndexPath:
In my UITableView I set the separatorStyle to UITableViewCellSeparatorStyleNone because in each row I want to show a set of pictures and it should like a grid without any separators.
In the simulator it looks like I want it to, but on my iPad (Version 5.0.1) I get a white line at the bottom of the HeaderCell. When I change the separatorColor to black the white line changes to black, which proves that it really is the separator. So it looks like my custom section view has a separator while the rows inside the sections do not.
I can "trick" the iPad to not show the separator when I define the header's height to 99 instead of 100 but that clearly is not the way to do it.
separatorColor = [UIColor clearColor]; ?
While I don't have the exact answer to your question, perhaps I can point you in the right direction for solving this issue.
I guess you've created custom cells? It sounds to me that it has something to do with the cell frame. In the speedy table view cell code from Tweetie I remember seeing the following code:
- (void)setFrame:(CGRect)newFrame
{
[super setFrame:newFrame];
CGRect bounds = self.bounds;
bounds.size.height -= 1; // keep space for de cell seperator
cellView.frame = bounds;
}
Perhaps Apple's default UITableViewCell code act the same when a frame is set and you could override it.
I am trying to set the backgroundView parameter of a UITableViewCell, but the backgroundView is overlapping the bounds of the cell. I have tried setting masksToBounds to YES, but that doesn't seem to make a difference. Please can you tell me where I am going wrong?
Here is an image showing my problem:
Here is my code:
UIImageView *iv = [[[UIImageView alloc] initWithFrame:cell.frame] autorelease];
[iv setImage:[UIImage imageNamed:#"paper"]];
[iv.layer setMasksToBounds:YES];
[cell.layer setMasksToBounds:YES];
[cell.contentView.layer setMasksToBounds:YES];
[cell setBackgroundView:iv];
Using masksToBounds doesn't work because the bounds of the cell are a rectangle.
Even if the corners of the cell are rounded, they're still part of the cell (but they contain transparent pixels). When a cell is displayed in a grouped table view, its background view (and its selected background view) is drawn in regard of its position in its section (middle, top, bottom, single).
So, if you want to provide a custom background view, you need to compute the position of the cell in its section and provide the adequate background :
either by using 4 different images
or by using the mask property of the background image's layer
or by subclassing UIView and implementing drawRect: so the graphic context is clipped before the image is drawn.
Are you setting every cell that background view, if so why don't you just set it to the table view background.
I have a weird problem in a custom UITableCell subClass.This custom cell has a pair of UILables that are multi-line and can contain varying amounts of text (up to 2000 characters). The custom tableCell has a layout method where I am calculating their frame's height using the code below, taking the device orientation into account:
if (isPortrait) {
presentationTextLabelSize = [presentationTextStr sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:CGSizeMake(portraitDescriptionWidth, 2000.0f) lineBreakMode:UILineBreakModeWordWrap];
presentationTextLabelRect = CGRectMake(60.0f, 25.0f, portraitDescriptionWidth, presentationTextLabelSize.height);
} else {
presentationTextLabelSize = [presentationTextStr sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:CGSizeMake(landscapeDescriptionWidth, 2000.0f) lineBreakMode:UILineBreakModeWordWrap];
presentationTextLabelRect = CGRectMake(60.0f, 25.0f, landscapeDescriptionWidth, presentationTextLabelSize.height);
}
self.presentationTextLabel.frame = presentationTextLabelRect;
I have the label's autoResizeMask set as follows:
self.presentationTextLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
I use the same calculation in the UITableViewController to set the row height.
Everything works perfectly, the label is sized to the correct height for it's width, and the cell autoResizes on device rotation, except that when the device is rotated to landscape the label's text sometimes extends out of the label's frame to the right, clear past the edge of the tableView. If I scroll the cell out of view and back again it's back to normal. I am logging the cell's width to the console, and it is correct, yet the text extends far past that width.
Any ideas what's joing on?
Thanks
The problem is, the tableView is not reloaded when the device is rotated to landscape. So, there is mismatch in updating the texts. Use [tableView reloadData]; at the place, where you find the device is changed to landscape mode.