1

I am trying to use the topEdgeEffect API in iOS 26, but even setting the effect style to ".soft" does not work:

class ViewController: UIViewController {

  var scrollView: UIScrollView!

  override func viewDidLoad() {
    super.viewDidLoad()
    
    // Create and configure UIScrollView
    scrollView = UIScrollView()
    scrollView.translatesAutoresizingMaskIntoConstraints = false
    scrollView.topEdgeEffect.style = .soft // <- This should work
    view.addSubview(scrollView)
    
    // Pin scrollView to fill the whole view
    NSLayoutConstraint.activate([
      scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
      scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
      scrollView.topAnchor.constraint(equalTo: view.topAnchor),
      scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
    ])
    
    // Create label with multiline text
    let label = UILabel()
    label.translatesAutoresizingMaskIntoConstraints = false
    label.numberOfLines = 0
    label.text = """
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
(More long text)
"""

    // Add label to scrollView
    scrollView.addSubview(label)
    
    // Constraints to make label fill scrollView width and define content height
    NSLayoutConstraint.activate([
      label.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor),
      label.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor),
      label.topAnchor.constraint(equalTo: scrollView.topAnchor),
      label.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),
      label.widthAnchor.constraint(equalTo: scrollView.widthAnchor) // fix width to scrollView width
    ])
  }
}

Example

Any help is appreciated! Running on Xcode 16.1.0 and an iOS 26.1 Simulator.

3
  • Don't know about uikit, but with SwiftUI, the scroll edge effect only works behind toolbars. Commented Nov 20 at 21:37
  • Unrelated to your question but you should be constraining the label to the scroll view's contentViewLayoutGuide. As you have it now, you won't be able to scroll since you are making the label the same size as the scroll view. Commented Nov 20 at 21:45
  • BenzyNeez: Interesting, I will check that! HangarRash: That's actually not correct, the scrolling works great. As the label is inside the scroll views content view, it fills it's parent and is scrollable Commented Nov 20 at 21:50

1 Answer 1

1

The top edge effect operates in relation to an overlaid glass top bar. You have no top bar. You need one. You might, for instance, like to wrap your view controller in a UINavigationController.

Sign up to request clarification or add additional context in comments.

2 Comments

Possibly it works in relation to other glass elements too but I have not yet had occasion to try that. My apps do use the top edge effect with a glass navigation bar and it works fine.
Thank you - that is correct. Wrapping it inside a navigation controller has fixed the issue indeed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.