Cell background not transparent - ios

Searching thorugh some posts I have tried without success to set the background of some dynamically generated cells to transparent.
In the storyboard I have a prototype table, under which I have an image. In storyboard I have set alpha to 0.3 for the prototype table, so that the image is partially visible. It renders as desired.
The problem is that the cells add an extra layer of color, so that the image is still visible, but a little less (as if the alpha was 0.6 for example). Actually, it seems like there are three layers. The table, the cell (which darkens the bg a little) and then another small rectangle inside each row around the text (which darkens the bg even more).
I've edited the function that generates the cells like so (based on what I've understood from the threads on this topic):
NSString *cellIdentifier = #"ItemCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
cell.textLabel.text = [self.labels objectAtIndex:indexPath.row]; // gets the text of the cell from an array
cell.textLabel.textColor = [UIColor colorWithRed:0.80 green:0.80 blue:0.80 alpha:1.0];
UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
backView.backgroundColor = [UIColor clearColor];
// I've also trued with = [UIColor colorWithRed:0. green:0 blue:0 alpha:0.0]
cell.backgroundView = backView;
The problem is that I still get that extra layer.

See, I have done changes somewhere in your code and try to use it.
[tableView setOpaque:NO];
NSString *cellIdentifier = #"ItemCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
//if cell is already created then reuse it no need to create unnecessarily.
if(cell= nil){//otherwise create new cells.
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;
}
cell.textLabel.text = [self.labels objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor colorWithRed:0.80 green:0.80 blue:0.80 alpha:1.0];

[tableView setOpaque:NO];
[tableView setBackgroundColor:[UIColor clearColor]];

Related

tableView elements limit, UITableView lagging

im wondering what is the limit of table View items, currently i'm using around ~120 elements, each element has photo 220x220x, when i exceed around 90-110 table view become a little bit laggy on iPhone 5, i tried to resize photos to 64x64 but, that was still laggy and images quality sucks. Memory usage is low, around 50mb, but when rolling tableview cpu usage jumps 30-90%. Im a little bit worried because i'm going to load ~800 items...
CODE:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"cel_f";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
Cell* cellF;
if(self.isFiltered)
cellF = [self.filteredTableData objectAtIndex:indexPath.row];
else
cellF = [_tableData objectAtIndex:indexPath.row];
cell.textLabel.text = cellF.name;
cell.backgroundColor = [UIColor clearColor];
cell.imageView.image = [UIImage imageNamed:cellF.andThumbImage];
UILabel *myLabel = [[UILabel alloc] init];
myLabel.frame = CGRectMake(295, 11, 25, 21);
[myLabel setFont:[UIFont systemFontOfSize:17]];
myLabel.textColor = [UIColor blackColor];
myLabel.text = #">";
UIView *bgColorView = [[UIView alloc] init];
bgColorView.backgroundColor = [UIColor colorWithRed:240 green:248 blue:255 alpha:0.25];
[cell setSelectedBackgroundView:bgColorView];
[cell addSubview:myLabel];
return cell;
}

Remove the borders of the cell in iOS7

I need to make the background of only one UITableViewCell fully transparent for iOS7 / iOS6.
What I did:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"ButtonsCell" forIndexPath:indexPath];
cell.backgroundColor = [UIColor clearColor];
cell.backgroundView = [UIView new];
cell.selectedBackgroundView = [UIView new];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
What I get:
in iOS6 everything is OK:
but in iOS7 there are two horizontal grey lines:
Is it possible to remove them?..
tableView.separatorColor = [UIColor clearColor];

Setting up a menu in UITableView showing the current item

I am using a slide in menu style which loads a UITableView. - ECSlidingViewController
I have about 7 cells in a table view setup as follows:
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.contentView.backgroundColor = [UIColor colorWithRed:75.0/255.0 green:83.0/255.0 blue:102.0/255.0 alpha:1.0];
UIView *topSplitterBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.bounds.size.width, 1)];
topSplitterBar.backgroundColor = [UIColor colorWithRed:62.0/255.0 green:69.0/255.0 blue:85.0/255.0 alpha:1];
[cell.contentView addSubview:topSplitterBar];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor colorWithRed:196.0/255.0 green:204.0/255.0 blue:218.0/255.0 alpha:1];
cell.textLabel.font = [UIFont systemFontOfSize:18.0f];
cell.textLabel.shadowColor = [UIColor colorWithRed:27.0/255.0 green:31.0/255.0 blue:41.0/255.0 alpha:1];
cell.textLabel.shadowOffset = CGSizeMake(0, 1);
UIView *selectedBg = [[UIView alloc] initWithFrame:cell.frame];
selectedBg.backgroundColor = [UIColor colorWithRed:50.0/255.0 green:56.0/255.0 blue:73.0/255.0 alpha:1];
cell.selectedBackgroundView = selectedBg;
What would be the best way to show a cell as the selectedBg if that is the currently displayed controller?
I can access the following for example:
if ([self.slidingViewController.topViewController isKindOfClass:[MESHomeViewController class]]) {
However, I am not sure where would be best practice to set this up? I can do it in the switch case for the cell label setup... For example:
switch ( indexPath.row ) {
case 0: {
if ([self.slidingViewController.topViewController isKindOfClass:[MESHomeViewController class]]) {
cell.contentView.backgroundColor = [UIColor colorWithRed:50.0/255.0 green:56.0/255.0 blue:73.0/255.0 alpha:1];
}
cell.textLabel.text = NSLocalizedString(#"LMGames", #"Left Menu - Games");
break ;
However, when a new item is selected from the menu I would need to reload the table each time, is that good? Completing a self.tableView reloadData each time a cell is selected, or is there a better way to approach this?
Two ideas for you:
Set the selectedBg in the didSelectRowAtIndexPath method in order to set the selected cell.
Keep an integer reference to the currently selected row and the previously selected row and then refresh only those rows by using a method similar to: How to reload and animate just one UITableView cell/row?
I hope that helps!

adding UIView into subView of cell, UITableViewController

Im adding 2 texts into a cell of a table. What I am doing is
UITableViewCell *cell =nil;
NSString *CellIdentifier = #"Cell";
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
[[UILabel alloc] initWithFrame:CGRectMake(80.0, 0.0, 220.0, 10.0)];
mainLabel.tag = 1003;
mainLabel.text = #"Text 1";
mainLabel.textAlignment = UITextAlignmentLeft;
mainLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|
UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:mainLabel];
}
I do the same thing to add secondLabel to a cell.
What is displaying on the simulator is
Now the problem is the background of 2 UILabel is not the same with the background of the cell ( my cells are grouped in the table view )
Does anyone know how to fix this problem.
Any comments are welcomed here
Thanks
If I have understand well the question, you need to delete the UILabel background because you want to show the UITableViewCell background instead. So I think you only have to do that:
mainLabel.backgroundColor = [UIColor clearColor];
Like the answer above, you should set the same color for both of the view.
cell.backgroundColor = [UIColor clearColor];
or you can set the color of the View you set.

UITableViewCell with accessory

I got an app with UITableView. Every cell has accessory. But i cant set backgroundColor ti this cells.
I tried to set backgrounColors in this ways:
cell.contentView.backgroundColor =[UIColor redColor];
cell.backgroundView.backgroundColor = [UIColor redColor];
cell.backgroundColor = [UIColor redColor];
But only contentView work. How can i do it? Thnx
the second way cell.backgroundView.backgroundColor = [UIColor redColor]; is not that wrong. Unfortunately there is no backgroundView until you create one. You have to create an UIView and set it as background of the cell.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:#"Cell"];
UIView *background = [[UIView alloc] initWithFrame:CGRectZero];
background.backgroundColor = [UIColor redColor];
cell.backgroundView = background;
}

Resources