I'm trying to avoid adding any code to my iOS project that has to do with visual set up since that's what Interface Builder is supposed to streamline for you.
So I'm trying to set up the prototype cell in IB and then just call:
TableCell *cell = [self.tableView dequeueReusableCellWithIdentifier:#"TableCell"];
The problem is if I change the background color for the cell in IB it remains white when I run my application. I can preset the color of the label fine but not the background color attribute in the Table Cell.
As an additional note, I can see that the UIView that is the backgroundView inside the cell is null after breakpointing and inspecting the variable after it's been initialized.
UPDATE
I'm getting the impression that the option for background color in IB is essentially useless? I'd rather not believe that.
You cannot do that unfortunately.
Change the background colour of the cell in tableView:willDisplayCell:forRowAtIndexPath:
From the documentation of UITableViewCell:
Note: If you want to change the background color of a cell (by setting the background color of a cell via the backgroundColor property declared by UIView) you must do it in the tableView:willDisplayCell:forRowAtIndexPath: method of the delegate and not in tableView:cellForRowAtIndexPath: of the data source. Changes to the background colors of cells in a group-style table view has an effect in iOS 3.0 that is different than previous versions of the operating system. It now affects the area inside the rounded rectangle instead of the area outside of it.
In interface builder, add a view as a subview of the cell, that will be your background view. You can then add all labels or anything else as subviews to that view. Change that views background color as you want.
I think this is probably a bug in IB. You can add views to that bar at the bottom of the controller, and then connect those views to the backgroundView and selectedBackgroundView properties of the cell. However, the backgroundView's color doesn't work, while the selectedBackgroundView's color does work correctly. If you add a background view in code to a custom table view cell and give it a backgroundColor, that does work.
Related
I have set my tableView's background color, and I want there is space(10px) around each cell show that color.
e.g.(ignore the red line)
What I am doing now is make the cell embed a smaller view, and set the cell's background to be clear. But it is annoying to create such embed view again and again.
So, I am seeking for a better solution, I believe it would be good if i can increase separator's height. But the old answers did not solve my problem.
(How to increase the UITableView separator height?)
EDIT:
However, if I add my own separator in cell. I may not able to set the cell having round corner
Set the tableView's separatorStyle to .None.
Create a custom UITableViewCell subclass.
In the storyboard (or xib if you created one for the custom cell), add a subview that's inset the amount that you want padded on all four sides.
If you want rounded views, do that on the custom cell's subview (e.g. subview.layer.cornerRadius = 10.0, subview.layer.masksToBounds = true).
Set the custom cell's ContentView to have a clear background.
Set the table view's background to that lovely shade of blue.
Set the cell subview's background color to white.
You don't have to use the cell repeatedly in InterfaceBuilder. Just give the cell an ID, and in your implementation of the table view's data source, dequeue a cell instance using that ID and set the values of the labels inside it.
Have you thought of just making the cell height taller and putting your own separator on the bottom of your custom cells? Nice table layout by the way.
Does anybody have the slightest idea on how I can achieve this type of effect on my table view cells?
or do you guys know a blog, Git, Repo that has nice TableViewCell make ups? thanks
In your storyboard, make everything transparent and set those images as your background.
Then you can use '
UIVisualEffectView | UIVisualEffectView with Blur class
' to set those blurs on your custom cells, make sure that your cell's background color is also in transparent mode.
or use
CAGradientLayer Class
to set them up.
If table's cell are static then you can create static custom cell in storyboard, Use Pin option in storyboard set left and right constraint for auto layout. Use background image and UILabel for creating for creating cell.
check the below link, it will help you.
use your own background image and font colur.
Customize UITableView and UITableViewCell
http://www.appcoda.com/ios-programming-customize-uitableview-storyboard/
So this problem is pretty weird and a little difficult to describe. Essentially I have a UITableView where each cell has an image, and a UIView covering part of the image. The UIView has it's background colour set to about 30% transparent white, giving it the appearance of washing out the image beneath. There's also some labels and such on it. All these views are added to a single parent container view, which is finally added to the cell's contentView. This all works fine - until I try to select the cell. For some reason, whenever the cell is highlighted, the backgroundColor property on each and every one of those views is set to clear, until the cell is unhighlighted (at which point the old colour returns).
Can anyone explain why this happens, and more important if there's a way to fix it? At most I could create a single pixel image of white, turn the UIView into a UIImageView, and set it's image to that pixel - but that's inelegant at best. Any suggestions?
When you select the cell, the implementation of setSelected:animated: is called and set the background color of all the views included in this cell to transparent.
Simply, you can just disable the selection of the cell by setting its selectionStyle to None:
cell.selectionStyle = UITableViewCellSelectionStyleNone;
Or, if you want to use the result of selection, you can override the setSelected:animated: method and reset the background color of your UIView
I created a custom UITableViewCell in a MonoTouch app I am building. Inside the cell I am succesfully setting:
Accessory = UITableViewCellAccessory.DisclosureIndicator;
However when I attempt to change the background color of the AccessoryView my app crashes because AccessoryView is null:
AccessoryView.BackgroundColor = UIColor.White;
As a matter of fact the only view within the cell that is not null is the ContentView.
Anyone has an idea why the AccessoryView is Null?
Accessory and AccessoryView properties are related but do not change each others.
When you set your own custom view in AccessoryView then the value of Accessory will be ignored the the UITableViewCell.
Anyone has an idea why the AccessoryView is Null?
Likewise if you set an Accessory then you do not get access to the stock view (thru the AccessoryView property) and events when supported, e.g. touch events for DisclosureButton, will be the cell (since you can't access the view).
If you want a custom looking accessory view then you can create one yourself and assign it to the AccessoryView property.
My original issue was that I was adding a an Accessory to the cell but the background of that accessory would not be the same as the background of the rest of the cell. It was getting the background of the underlying table view which was not what I wanted. When I tried to set the AccessoryView.Background color to what I wanted (thinking that that was culprit), the AccessoryView was null.
What I ended up doing to solve my issue was to create a new UIView with the background color I wanted and set that as my cells BackgroundView (since that was also null initially). This fixed my issue and my cell has the proper color everywhere.
I've got a custom table view cell defined within a nib, I'm finding that whatever colour I set for view background in IB isn't being applied (why its not being applied is another question I have). So within the table view controller I added:
[localCell.contentView setBackgroundColor:LIGHT_BACKGROUND];
The cell colour now comes out as expected, however if in IB I set the accessory to anything other than none then the colour of the cell is shifted to the left by an amount about equal to the size of the indicator, behind the indicator I can see the background colour for the table.
Why is this happening?
TIA
The accessory view is not contained within the content view. You probably need to set the color of the background view of your cell rather than the content view.
[localCell.backgroundView setBackgroundColor:LIGHT_BACKGROUND];