Today Cell Background Color
AppStore JSON APIs
This video, we'll cover one final aspect of our today cells and that is to control the background color as we choose. This change is quite small but it does present us with a few bugs in our AppFullscreenController display. I'll go over how to set up constraints to fix this and how to alter our animations to take them into account. Enjoy.

Comments (9)
Tube
4 years ago
Programming is a dirty business. It's not for sissies.
johnrm9
4 years ago
Hi Brian, Does using the safeAreaLayoutGuide for the top anchor in the TodayCell class also work like changing the top anchor constants? As in: stackView.anchor(top: safeAreaLayoutGuide.topAnchor, leading: leadingAnchor, bottom: bottomAnchor, trailing: trailingAnchor, padding: .init(top: 24, left: 24, bottom: 24, right: 24)) Thanks
Brian Voong
4 years ago
johnrm9
4 years ago
Brian, Oh, I used your lovely anchor extension in the TodayController to set up the saved constrains for the fullscreenView (was named the redView) and used a small CGRect extension: extension CGRect { var topLeftEdge: UIEdgeInsets { return .init(top: self.origin.y, left: self.origin.x, bottom: 0, right: 0) } } override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { ... guard let cell = collectionView.cellForItem(at: indexPath) else { return } guard let startingFrame = cell.superview?.convert(cell.frame, to: nil) else { return } self.startingFrame = startingFrame let anchors = fullscreenView.anchor(top: view.topAnchor, leading: view.leadingAnchor, padding: startingFrame.topLeftEdge, size: startingFrame.size) // This works pretty good! Oh, the bottom and trailing were defaulted to nil (topConstraint, leadingConstraint, widthConstraint, heightConstraint) = (anchors.top, anchors.leading, anchors.width, anchors.height) // Save the constraints for later ... self.view.layoutIfNeeded() Thanks
Brian Voong
4 years ago
Yu Hao Chen
4 years ago
Hi, Brian Why not change status bar background color? like.. // Creat Color Image public func createGradientImage() -> UIImage? { var image: UIImage? = nil UIGraphicsBeginImageContext(bounds.size) if let context = UIGraphicsGetCurrentContext() { render(in: context) image = UIGraphicsGetImageFromCurrentImageContext() } UIGraphicsEndImageContext() return image } // Set StatusBar BackgroundColor Support Gradient public func setupStatusBarView(colors: [UIColor], startPoint: CGPoint = .init(x: 0, y: 0.5), endPoint: CGPoint = .init(x: 1, y: 0.5)) { let statWindow = UIApplication.shared.value(forKey:"statusBarWindow") as! UIView let statusBarFrame = UIApplication.shared.statusBarFrame let gradientLayerStatusBar = CAGradientLayer(frame: statusBarFrame, colors: colors) gradientLayerStatusBar.startPoint = startPoint gradientLayerStatusBar.endPoint = endPoint if let image = gradientLayerStatusBar.createGradientImage() { statWindow.subviews.first?.backgroundColor = UIColor(patternImage: image) } }
Brian Voong
4 years ago
chao700716
4 years ago
I've put this snippet of code in my AppFullScreenController for changing the color of the status bar. **************************************************************************************************** override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) if let StatusbarView = UIApplication.shared.value(forKey: "statusBar") as? UIView { StatusbarView.backgroundColor = todayItem?.backgroundColor } **************************************************************************************************** And then I change the color back to its original setting in handleRemoveRedView(). It looks working in my simulator. }
Tokyojogo
4 years ago
Hi Brian, you used the contentInset to add spacing at the bottom. Can't we use this for the header problem as well? Thanks.
malrhex
4 years ago
Bro, from minute 5:21 until 7:21 it's a waste, I mean you only needed to add padding instead of 24, just change it to 40. You will save 2 minutes of your life. For time sake!
malrhex
4 years ago
But good thing to learn more ways. Appreciated!
jdhindsa
4 years ago
How on earth would anyone know what property to set to make the color of the top of the screen the same as the header cell? contentInsetAdjustmentBehaviour? This is what I hate about iOS development... how would you ever know that.. the description of this attribute is: "This property specifies how the safe area insets are used to modify the content area of the scroll view. The default value of this property is UIScrollView.ContentInsetAdjustmentBehavior.automatic." To me, that wouldn't ring a bell that it has to do with color.
Kritbovorn Taweeyossak
3 years ago
iOS13 // Find Height of StatusBar frame let statusBarHeight = UIApplication.shared.windows.filter({$0.isKeyWindow}).first?.windowScene?.statusBarManager?.statusBarFrame ?? CGRect.zero tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: statusBarHeight.height, right: 0)
Braqa
3 years ago
Hi Brian, when I don't add this line: tableView.contentInsetAdjustmentBehavior = .never The white space is like it's an invisible navigation controller. When I add the line will fill that white space, but not the status bar. I'm using iOS 13 with Swift 5. Any idea where the problem may be, or what solution will solve the problem?
Brian Voong
3 years ago
HELP & SUPPORT