UITableView clear background
// Fix for iOS 7 to clear backgroundColor
cell.backgroundColor = [UIColor clearColor];
cell.backgroundView = [[UIView new] autorelease];
cell.selectedBackgroundView = [[UIView new] autorelease];
in cellForRowAtIndexPath
Also, make sure that your tableview actually has transparent background (in storyboard):
How do I make this UITableView clear (transparent) in Swift 3
Note: Below code been tested in Swift 3
.
Method 1:
Select your tableViewCell from your storyboard
and goto Attributes Inspector
under View
change Background
to clear
Method 2: Try below code inside your cellForRowAt
cell.layer.backgroundColor = UIColor.clear.cgColor
Note : If above method didn't works.try clear your project build by pressing shift + option + command + k
Update: Update your cellForRowAt
from below code...
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath as IndexPath)
cell.textLabel?.text = communities[indexPath.row]
cell.textLabel?.font = UIFont(name: "Avenir", size: 12)
cell.textLabel?.textColor = UIColor.red // set to any colour
cell.layer.backgroundColor = UIColor.clear.cgColor
return cell
}
How to create a UITableViewCell with a transparent background
If both the other options didn't work try this
UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;
Custom UITableviewCell transparent background error Swift 4
Try
self.backgroundColor = UIColor.clear
self.isOpaque = false
Repeat it for contentView & bg
How to set clear background for UITableView Header with opaque body
After a couple days I was able to figure it out. The premise of the solution is to add a subview to the backgroundView of your table and change the subview's frame as you scroll.
The relevant code in viewDidLoad:
...
// Create the UIView that will become the tableView backgroundView
UIView *tableViewBackground = [[UIView alloc] initWithFrame:self.tableView.frame];
tableViewBackground.backgroundColor = [UIColor clearColor];
// Create the opaque backgroundView and set the frame so that it starts below the headerView
partialBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 250, 320.0, self.view.frame.size.height)];
partialBackgroundView.backgroundColor = [UIColor redColor];
// Add the partial background to the main background view and apply it to the tableView
[tableViewBackground addSubview:solidTableBodyBackgroundView];
self.tableView.backgroundView = tableViewBackground;
...
And then as you scroll, you can update the "visible window" in scrollViewDidScroll:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat scrollOffset = scrollView.contentOffset.y;
partialBackgroundView.frame = CGRectMake(0, 250 - scrollOffset, 320, self.view.frame.size.height);
// Other parallax code for scrolling
}
There may be better ways of doing this, but I found this to be pretty simple and it worked well.
Swift - set clear background color in UITableView
In your WhishlistTableViewController
class:
override func viewDidLoad() {
super.viewDidLoad()
// set background to clear
tableView.backgroundColor = .clear
// add clear view as tableFooterView
// to prevent empty cells
let v = UIView()
v.backgroundColor = .clear
tableView.tableFooterView = v
// ... rest of table setup
tableView.register(WishCell.self, forCellReuseIdentifier: "WishCell")
}
Now you no longer need v.view.backgroundColor = .clear
in your declaration.
Another option if, for example, you sometimes want to use an instance of WhishlistTableViewController
without the transparent background, change your declaration from:
let theTableView: WhishlistTableViewController = { ... }
to:
lazy var theTableView: WhishlistTableViewController = { ... }
Transparent background in grouped UITableView - iPhone
Instead of using
UIColor *bgColor = [[UIColor alloc] initWithWhite:1 alpha:0.0];
historyTable.backgroundColor = bgColor;
Just use:
historyTable.backgroundColor = [UIColor clearColor];
That also clears up the memory leak you were creating.
How to set clear background in table view cell swipe action?
You can just set the alpha value to 0 for background color of the action:
let modifyAction = UIContextualAction(style: .normal, title: "", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("Update action ...")
success(true)
})
modifyAction.backgroundColor = UIColor.init(red: 0/255.0, green: 0/255.0, blue: 0/255.0, alpha: 0.0)
Related Topics
Swiftui Generic Pull to Refresh View
Alternative to Usernotificationcenterdelegate's Willpresent When App Is in Background
Fbsdkaccesstoken Currentaccesstoken Nil After Quitting App
What Impact Does Simulated Metrics Have
This Class Is Not Key Value Coding-Compliant for the Key Xxxxxx
Error: Uicollectionview Must Be Initialized with a Non-Nil Layout Parameter
Will iOS Region Monitoring Call Didenterregion on My App If My App Is in a Terminated State
Aes/Cbc/Pkcs5Padding in iOS Objective C Result Differs from Android
Dismissing Both Uinavigation Views and Modal Views at Once Programmatically
Undefined Symbols for Architecture I386: "_Objc_Class_$_Zipexception", Referenced From: Error
Button Action in Mkannotation View Not Working
How to Determine the True Data Type of an Nsnumber
Create and Perform Segue Without Storyboards
iOS - Swift - Function That Returns Asynchronously Retrieved Value
How to Know Users Click Fast Forward and Fast Rewind Buttons on the Playback Controls in Iphone