I'm trying to use a check mark in the UITablewViewCell which is a custom cell that has 3 labels. The problem is that no matter what resolution or dimensions I use for the check mark image, it's looks pixelated as in the image below. I tried 40x40, 60x60 and 80x80 pixels and also 72 Dpi and 300 Dpi with no success. Here is the code for the custom cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"MyCell";
//UILabel *mainLabel, *secondLabel, *thirdLabel;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryNone;
//Add the 3 labels
mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(40.0, 5.0, 180.0, 21.0)];
mainLabel.tag = MAINLABEL_TAG;
//mainLabel.font = [UIFont systemFontOfSize:14.0];
//mainLabel.font = [UIFont fontWithName:#"Geeza Pro Bold" size:17.0];
mainLabel.font = [UIFont boldSystemFontOfSize:13];
mainLabel.textAlignment = UITextAlignmentLeft;
mainLabel.textColor = [UIColor blackColor];
mainLabel.highlightedTextColor = [UIColor whiteColor];
mainLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:mainLabel];
secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(40.0, 21.0, 190.0, 21.0)];
secondLabel.tag = SECONDLABEL_TAG;
//secondLabel.font = [UIFont systemFontOfSize:12.0];
//secondLabel.font = [UIFont fontWithName:#"Geeza Pro" size:15.0];
secondLabel.font = [UIFont systemFontOfSize:13];
secondLabel.textAlignment = UITextAlignmentLeft;
secondLabel.textColor = [UIColor darkGrayColor];
secondLabel.highlightedTextColor = [UIColor whiteColor];
secondLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:secondLabel];
thirdLabel = [[UILabel alloc] initWithFrame:CGRectMake(240.0, 11.0, 70.0, 21.0)];
thirdLabel.tag = THIRDLABEL_TAG;
//thirdLabel.font = [UIFont systemFontOfSize:12.0];
//thirdLabel.font = [UIFont fontWithName:#"Geeza Pro Bold" size:17.0];
thirdLabel.font = [UIFont boldSystemFontOfSize:13];
thirdLabel.textAlignment = UITextAlignmentRight;
thirdLabel.textColor = [UIColor blackColor];
thirdLabel.highlightedTextColor = [UIColor whiteColor];
thirdLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:thirdLabel];
}
else
{
mainLabel = (UILabel *)[cell.contentView viewWithTag:MAINLABEL_TAG];
secondLabel = (UILabel *)[cell.contentView viewWithTag:SECONDLABEL_TAG];
thirdLabel = (UILabel *)[cell.contentView viewWithTag:THIRDLABEL_TAG];
}
//If the requesting table view is the search display controller's table view, configure the cell using the filtered content, otherwise use the main list.
Car *car = nil;
if (tableView == self.searchDisplayController.searchResultsTableView)
{
car = [self.filteredListContent objectAtIndex:indexPath.row];
}
else
{
car = [self.listContent objectAtIndex:indexPath.row];
}
NSString *carName = [NSString stringWithFormat:#"%#",car.deviceName];
NSString *carDetails = [NSString stringWithFormat:#"%# at %#",car.date,car.location];
NSString *carSpeed = [NSString stringWithFormat:#"%# km/h",car.speed];
mainLabel.text = carName;
secondLabel.text = carDetails;
thirdLabel.text = carSpeed;
//Check for selection
if (car.isSelected == YES)
{
[cell.imageView setImage:[UIImage imageNamed:#"new_checkmark.png"]];
}
else
{
[cell.imageView setImage:nil];
}
return cell;
}
And here is the screen shot:
create two images named new_checkmark.png & new_checkmark#2x.png.
new_checkmark#2x.png must be doubled dimension of new_checkmark.png in proportion.
in coding dont use extension, onlu give name like this
[cell.imageView setImage:[UIImage imageNamed:#"new_checkmark"]];
Related
In Apples' own documentation,
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html
it has recommended using UITextAlignmentRight in the following snippet on that page :
Listing 5-7 Adding subviews to a cell’s content view
#define MAINLABEL_TAG 1
#define SECONDLABEL_TAG 2
#define PHOTO_TAG 3
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"ImageOnRightCell";
UILabel *mainLabel, *secondLabel;
UIImageView *photo;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 220.0, 15.0)];
mainLabel.tag = MAINLABEL_TAG;
mainLabel.font = [UIFont systemFontOfSize:14.0];
mainLabel.textAlignment = UITextAlignmentRight;
mainLabel.textColor = [UIColor blackColor];
mainLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:mainLabel];
secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 20.0, 220.0, 25.0)];
secondLabel.tag = SECONDLABEL_TAG;
secondLabel.font = [UIFont systemFontOfSize:12.0];
secondLabel.textAlignment = UITextAlignmentRight;
secondLabel.textColor = [UIColor darkGrayColor];
secondLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:secondLabel];
photo = [[UIImageView alloc] initWithFrame:CGRectMake(225.0, 0.0, 80.0, 45.0)];
photo.tag = PHOTO_TAG;
photo.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:photo];
} else {
mainLabel = (UILabel *)[cell.contentView viewWithTag:MAINLABEL_TAG];
secondLabel = (UILabel *)[cell.contentView viewWithTag:SECONDLABEL_TAG];
photo = (UIImageView *)[cell.contentView viewWithTag:PHOTO_TAG];
}
NSDictionary *aDict = [self.list objectAtIndex:indexPath.row];
mainLabel.text = [aDict objectForKey:#"mainTitleKey"];
secondLabel.text = [aDict objectForKey:#"secondaryTitleKey"];
NSString *imagePath = [[NSBundle mainBundle] pathForResource:[aDict objectForKey:#"imageKey"] ofType:#"png"];
UIImage *theImage = [UIImage imageWithContentsOfFile:imagePath];
photo.image = theImage;
return cell;
}
However, Xcode 7 compains that UITextAlignmentRight has been deprecated since iOS 6.0. However, Xcode does not say what to use in its place. Please recommend what to use instead of UITextAlignmentRight
You could use : NSTextAlignment
label.textAlignment = NSTextAlignmentRight
Although there are couple of posts in the site regarding UITableview cell repetition when scrolled, I could nt find the solution, perhaps because am pretty new to obj-c.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *cellIdentifier = [NSString stringWithFormat:#"cell%d",indexPath.row];
UILabel *firstlabel = nil;
UILabel *secondlabel = nil;
UILabel *thirdlabel = nil;
myTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if(!cell) {
cell = [[myTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
}
if (noOfRows < [_eachrow count]-1) {
_eachcolumn = [_eachrow[noOfRows] componentsSeparatedByString:#"|"];
firstlabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0, 142.0,tableView.rowHeight)];
firstlabel.font = [UIFont fontWithName:#"Verdana" size:12];
firstlabel.text = _eachcolumn[0];
firstlabel.textAlignment = ALIGN_LEFT;
firstlabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:firstlabel];
secondlabel = [[UILabel alloc] initWithFrame:CGRectMake(142.0, 0, 50.0,tableView.rowHeight)];
secondlabel.font = [UIFont fontWithName:#"Verdana" size:12];
secondlabel.text = _eachcolumn[1];
secondlabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:secondlabel];
thirdlabel = [[UILabel alloc] initWithFrame:CGRectMake(192.0, 0, 60.0,tableView.rowHeight)];
thirdlabel.font = [UIFont fontWithName:#"Verdana" size:12];
thirdlabel.text = _eachcolumn[2];
thirdlabel.textAlignment = ALIGN_CENTER;
thirdlabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:thirdlabel];
noOfRows++;
return cell;
}
else return cell;
}
So, my problem is when I scroll up or down, the cells keep placed at wrong rows without a pattern. Please help me resolve this issue. Thanks in advance
The problem occurs because the cells are reusable and you need to override the values each time in cellForRow .
Try this instead:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *cellIdentifier = [NSString stringWithFormat:#"cell%d",indexPath.row];
myTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(!cell) {
cell = [[myTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
UILabel *firstlabel = nil;
UILabel *secondlabel = nil;
UILabel *thirdlabel = nil;
_eachcolumn = [_eachrow[noOfRows] componentsSeparatedByString:#"|"];
firstlabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0, 142.0,tableView.rowHeight)];
firstlabel.font = [UIFont fontWithName:#"Verdana" size:12];
firstlabel.text = _eachcolumn[0];
firstlabel.textAlignment = ALIGN_LEFT;
firstlabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleHeight;
firstlabel.tag = 10;
[cell.contentView addSubview:firstlabel];
secondlabel = [[UILabel alloc] initWithFrame:CGRectMake(142.0, 0, 50.0,tableView.rowHeight)];
secondlabel.font = [UIFont fontWithName:#"Verdana" size:12];
secondlabel.text = _eachcolumn[1];
secondlabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleHeight;
secondlabel.tag = 20;
[cell.contentView addSubview:secondlabel];
thirdlabel = [[UILabel alloc] initWithFrame:CGRectMake(192.0, 0, 60.0,tableView.rowHeight)];
thirdlabel.font = [UIFont fontWithName:#"Verdana" size:12];
thirdlabel.text = _eachcolumn[2];
thirdlabel.textAlignment = ALIGN_CENTER;
thirdlabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleHeight;
thirdlabel.tag = 30;
[cell.contentView addSubview:thirdlabel];
return cell;
}
else
{
((UILabel *)[cell.contentView viewWithTag:10]).text = _eachcolumn[1];
((UILabel *)[cell.contentView viewWithTag:20]).text = _eachcolumn[2];
((UILabel *)[cell.contentView viewWithTag:30]).text = _eachcolumn[3];
return cell;
}
}
A UILabel in my App is behaving unusually and I'm wondering if anyone has any ideas or suggestions on how to resolve it.
1.First I set the frames of the labels which will both appear inside the cell of a tableView.
CGRect CellFrame = CGRectMake(0, 0, 300, 75);
CGRect Label1Frame = CGRectMake(10, 5, 290, 20);
CGRect Label2Frame = CGRectMake(0, 20, 290, 50);
UILabel *lblTemp;
UITableViewCell *cell = [[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier];
Then I set the properties of labels
1.
lblTemp = [[UILabel alloc] initWithFrame:Label1Frame];
lblTemp.tag = 1;
lblTemp.font = [UIFont fontWithName:#"Helvetica" size:12.0];
lblTemp.textColor = [UIColor blackColor];
lblTemp.lineBreakMode = UILineBreakModeWordWrap;
lblTemp.numberOfLines = 0;
[cell.contentView addSubview:lblTemp];
//Initialize Label with tag 2.
lblTemp = [[UILabel alloc] initWithFrame:Label2Frame];
lblTemp.tag = 2;
lblTemp.font = [UIFont fontWithName:#"Helvetica" size:10];
lblTemp.textColor = [UIColor lightGrayColor];
lblTemp.lineBreakMode = UILineBreakModeWordWrap;
lblTemp.numberOfLines = 0;
[cell.contentView addSubview:lblTemp];
return cell;
3.Then I setup the contents of the cell
//set up the cell
UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
UILabel *lblTemp2 = (UILabel *)[cell viewWithTag:2];
CaseFeed *aCaseFeed = [[CaseFeed alloc] init];
aCaseFeed = [CaseFeedbook objectAtIndex:indexPath.row];
lblTemp1.text = [NSString stringWithFormat:#"%#", aCaseFeed.title];
lblTemp2.text = [NSString stringWithFormat:#"%#", aCaseFeed.description];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
PROBLEM: The contents of lblTemp2 (the second label in the cell) will span 2 or more lines. During runtime, when the text of lblTemp2 is populated, the first two lines appear perfectly, however the third line starts outside the left side of the frame.
Any ideas on how to resolve this? Why is this happening?
Use the following code to setup your cell of a tableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
else
{
for (id v in cell.contentView.subviews)
{
UIView *realV = (UIView *) v;
[realV removeFromSuperview];
}
}
CGRect CellFrame = CGRectMake(0, 0, 300, 75);
CGRect Label1Frame = CGRectMake(10, 5, 290, 20);
CGRect Label2Frame = CGRectMake(0, 20, 290, 50);
UILabel *label1 = [[UILabel alloc] init];
label1.frame = Label1Frame;
label1.tag = 1;
label1.font = [UIFont fontWithName:#"Helvetica" size:12.0];
label1.textColor = [UIColor blackColor];
label1.lineBreakMode = UILineBreakModeWordWrap;
label1.numberOfLines = 0;
[cell.contentView addSubview:label1];
UILabel *label2 = [[UILabel alloc] init];
label2.frame = Label2Frame;
label2.tag = 2;
label2.font = [UIFont fontWithName:#"Helvetica" size:10.0];
label2.textColor = [UIColor lightGrayColor];
label2.lineBreakMode = UILineBreakModeWordWrap;
label2.numberOfLines = 0;
[cell.contentView addSubview:label2];
CaseFeed *aCaseFeed = [[CaseFeed alloc] init];
aCaseFeed = [CaseFeedbook objectAtIndex:indexPath.row];
label0.text = [NSString stringWithFormat:#"%#", aCaseFeed.title];
label1.text = [NSString stringWithFormat:#"%#", aCaseFeed.description];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
Hope this helps
I'm using Grouped UITableView and add UITableViewCells two UILabel's and adding them to the contentView of the cell. I am also implementing edit mode in my app on this UITableView.
I use the
lblDetail.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth; in order to decrease width of the text so the delete red button showing in edit mode will not cover my text.
Now what I see is when I scroll my table not in edit mode the labels show two times as if it is in in edit mode and out of edit mode at the same time.
This is the code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
CGRect DetailLabelFrame = CGRectMake(52, 25, 200, 35);
CGRect TitleLabelFrame = CGRectMake(52, 5, 200, 25);
lblDetail = [[UILabel alloc]init];
lblTitle = [[UILabel alloc]init];
lblDetail.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
lblTitle.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
lblDetail.frame = DetailLabelFrame;
lblDetail.lineBreakMode = UILineBreakModeWordWrap;
lblDetail.backgroundColor = [UIColor clearColor];
lblDetail.numberOfLines = 2;
lblTitle.frame = TitleLabelFrame;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.frame = TitleLabelFrame;
[lblDetail setFont:[UIFont fontWithName:#"Arial" size:14]];
[lblTitle setFont:[UIFont fontWithName:#"Arial-BoldMT" size:15]];
lblDetail.textAlignment = UITextAlignmentRight;
lblTitle.textAlignment = UITextAlignmentRight;
lblTitle.text = #"054-9700583";
lblDetail.text = #"שאלה:במה אפשר לעזור לך?";
[cell.contentView addSubview:lblDetail];
[cell.contentView addSubview:lblTitle];
cell.imageView.layer.masksToBounds = YES;
cell.imageView.layer.cornerRadius = 5.0;
cell.imageView.image = [UIImage imageNamed:#"girl.png"];
[lblDetail release];
[lblTitle release];
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
CGRect DetailLabelFrame = CGRectMake(52, 25, 200, 35);
CGRect TitleLabelFrame = CGRectMake(52, 5, 200, 25);
lblDetail = [[UILabel alloc]init];
lblTitle = [[UILabel alloc]init];
lblDetail.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
lblTitle.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
lblDetail.frame = DetailLabelFrame;
lblDetail.lineBreakMode = UILineBreakModeWordWrap;
lblDetail.backgroundColor = [UIColor clearColor];
lblDetail.numberOfLines = 2;
lblTitle.frame = TitleLabelFrame;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.frame = TitleLabelFrame;
[lblDetail setFont:[UIFont fontWithName:#"Arial" size:14]];
[lblTitle setFont:[UIFont fontWithName:#"Arial-BoldMT" size:15]];
lblDetail.textAlignment = UITextAlignmentRight;
lblTitle.textAlignment = UITextAlignmentRight;
[cell.contentView addSubview:lblDetail];
[cell.contentView addSubview:lblTitle];
lblDetail.tag = 10;
lblTitle.tag = 11;
}
lblDetail = (UILabel*)[cell.contentView viewWithTag:10];
lblTitle = (UILabel*)[cell.contentView viewWithTag:11];
lblTitle.text = #"054-9700583";
lblDetail.text = #"שאלה:במה אפשר לעזור לך?";
cell.imageView.layer.masksToBounds = YES;
cell.imageView.layer.cornerRadius = 5.0;
cell.imageView.image = [UIImage imageNamed:#"girl.png"];
[lblDetail release];
[lblTitle release];
return cell;
}
Your cell contents was overlapping may be it will help you.Still now if you face same problem the knock me without any hesitation.
If this is only happening when you're scrolling it may be because when a cell is being reused it's creating a new set of labels in addition to what's already in the reused cell.
What you can try to do is move these two lines into your if (cell == nil ) block:
lblDetail = [[UILabel alloc]init];
lblTitle = [[UILabel alloc]init];
That way when a cell is being reused it'll continue to use the existing lblDetail and lblTitle instead of creating a new one.
I have problem with the cell background color becoming clearcolor always. I set the uiview background color to gray color, tableview background color to clear color and I did not set tableviewcell background color to clear color. But the cell background always appears grey. Can any one have any idea about this.
Thanks
-(void)viewDidLoad
{
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"TableBackGround.png"]];
Acc_Details_TView.backgroundColor = [UIColor clearColor];
Acc_Details_TView.rowHeight = 40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"TransCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
switch ([Acc_Details_SegCtrl selectedSegmentIndex]) {
case 0:{
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"TableCell"] autorelease];
cell.backgroundColor =[UIColor clearColor];
cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
cell.detailTextLabel.text = [[transcationsList objectAtIndex:([indexPath row])] valueForKey:#"Date"];
cell.detailTextLabel.font = [UIFont systemFontOfSize:12];
}
NSString *titleName =[[transcationsList objectAtIndex:([indexPath row])] valueForKey:#"Title"] ;
if ([titleName length] > 19) {
cell.textLabel.text = [titleName substringWithRange:NSMakeRange(0, 20)];
}
else{
cell.textLabel.text = titleName;
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UILabel * acc_Amount = [[UILabel alloc] initWithFrame:CGRectMake(220, 5, 60,10)];
acc_Amount.textAlignment = UITextAlignmentRight;
acc_Amount.backgroundColor = [UIColor clearColor];
acc_Amount.text = [[transcationsList objectAtIndex:([indexPath row])] valueForKey:#"Amount"];
acc_Amount.font = [UIFont boldSystemFontOfSize:14];
[cell.contentView addSubview:acc_Amount];
UILabel * balance_Amount = [[UILabel alloc] initWithFrame:CGRectMake(220, 23, 60,10)];
balance_Amount.textAlignment = UITextAlignmentRight;
balance_Amount.text = #"$1234.50";
balance_Amount.backgroundColor = [UIColor clearColor];
balance_Amount.textColor = [UIColor grayColor];
balance_Amount.font = [UIFont systemFontOfSize:12];
[cell.contentView addSubview:balance_Amount];
return cell;
}
}
}
Try setting your cell's background colour in the method
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
rather than in your cellForRowAtIndexPath: method.
Your cells are not exactly transparent. Setting UITableView's backgroundColor does some crazy undocumented stuff. Best way to see this is to set it to some semi-transparent color like [UIColor colorWithWhite:0.5 alpha:0.5] by which you get something like this:
To fix your problem, you will have to set cells' contentView.backgroundColor and backgroundColors of all the subviews after setting tableView's. Here is your cellForRowAtIndexPath: updated with this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"TransCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIColor *cellBackgroundColor = [UIColor whiteColor];
switch ([Acc_Details_SegCtrl selectedSegmentIndex]) {
case 0:{
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"TableCell"] autorelease];
cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
cell.detailTextLabel.text = [[transcationsList objectAtIndex:([indexPath row])] valueForKey:#"Date"];
cell.detailTextLabel.font = [UIFont systemFontOfSize:12];
cell.accessoryView.backgroundColor = cellBackgroundColor;
cell.backgroundView.backgroundColor = cellBackgroundColor;
cell.contentView.backgroundColor = cellBackgroundColor;
cell.textLabel.backgroundColor = cellBackgroundColor;
cell.detailTextLabel.backgroundColor = cellBackgroundColor;
UIView *backView = [[UIView alloc] initWithFrame:cell.frame];
backView.backgroundColor = cellBackgroundColor;
cell.backgroundView = backView;
[backView release];
}
NSString *titleName =[[transcationsList objectAtIndex:([indexPath row])] valueForKey:#"Title"] ;
if ([titleName length] > 19) {
cell.textLabel.text = [titleName substringWithRange:NSMakeRange(0, 20)];
}
else{
cell.textLabel.text = titleName;
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UILabel * acc_Amount = [[UILabel alloc] initWithFrame:CGRectMake(220, 5, 60,10)];
acc_Amount.textAlignment = UITextAlignmentRight;
acc_Amount.backgroundColor = cellBackgroundColor;
acc_Amount.text = [[transcationsList objectAtIndex:([indexPath row])] valueForKey:#"Amount"];
acc_Amount.font = [UIFont boldSystemFontOfSize:14];
[cell.contentView addSubview:acc_Amount];
UILabel * balance_Amount = [[UILabel alloc] initWithFrame:CGRectMake(220, 23, 60,10)];
balance_Amount.textAlignment = UITextAlignmentRight;
balance_Amount.text = #"$1234.50";
balance_Amount.backgroundColor = cellBackgroundColor];
balance_Amount.textColor = [UIColor grayColor];
balance_Amount.font = [UIFont systemFontOfSize:12];
[cell.contentView addSubview:balance_Amount];
}
}
return cell;
}
I didn't understand your question. You set the table's background to grey, then clear, but you didn't set it as clear, and then it appears grey, which you didn't want even though you set it as grey?
table.backgroundColor = [UIColor clearColor];