How to create Liquid glass for custom view in Swift?

We have already discussed aboutΒ How to adopt Liquid Glass in UIButton in Swift?Β It’s easy to adopt liquid glass design in any view with SwiftUI, I will add separate post for that. In this post let’s discuss about – create liquid glass for custom view in Swift.

Apple just introducedΒ Liquid GlassΒ design in WWDC25 event. Here I am posting little snippet that how to apply liquid glass style to UILabel inΒ UIKitΒ with Swift Language.

Read more

How to adopt Liquid Glass in UIButton in Swift?

Yesterday we have already discussed about How to create Liquid Glass Button in SwiftUI? I thought many of the developers (even me) using the UIKit. So, let’s quickly check how to adopt Liquid Glass in UIButton.

UIKit - Liquid Glass UIButton in Swift

Apple just introducedΒ Liquid GlassΒ design in WWDC25 event. Here I am posting little snippet that how to apply liquid glass style toΒ UIButtonΒ inΒ UIKit with Swift Language.

Read more

iOS Lifecycle: Handling willEnterForeground in AppDelegate and SceneDelegate

Hope you guys already know that we need to migrate to scene-based life cycle in near future.

Below lines are written in this reference document provided by Apple.

In iOS 18.4, iPadOS 18.4, Mac Catalyst 18.4, tvOS 18.4, visionOS 2.4 and later, UIKit logs the this message for apps that haven’t adopted the scene-based life-cycle.

This process does not adopt UIScene lifecycle. This will become an assert in a future version.

Soon, all UIKit based apps will be required to adopt the scene-based life-cycle, after which your app won’t launch if you don’t. While supporting multiple scenes is encouraged, only adoption of scene life-cycle is required.

Here I am discussing about the methods applicationWillEnterForeground and sceneWillEnterForeground actually work same or not? As there are key differences let’s discuss in detail.

Read more

How to prevent screenshot for UIView in iOS?

iOS – Apple provides screenshot detection notification but not providing direct solution for prevention.

Here I found solution for preventing screenshot taking from the UIView. It’s a simple extension of the UIView that allows to hide it from screen-capturing and also from screen recording. The solution uses ability of UITextField to hide a password from capturing.

extension UIView {
func preventScreenshot() {
DispatchQueue.main.async {
let field = UITextField()
field.isSecureTextEntry = true
self.addSubview(field)
field.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
field.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
self.layer.superlayer?.addSublayer(field.layer)
field.layer.sublayers?.first?.addSublayer(self.layer)
}
}
}

Usage:

viewSecure.preventScreenshot()

So, when you take screenshot the logic of text field secure entry (password text field) will not allow to take screenshot of that part.

ScrollView Screenshot Prevention

Update: Here is recursive function for preventing screenshot.

extension UIView {
func preventScrollViewScreenshotRecursive() {
guard superview != nil else {
for subview in subviews {
subview.preventScrollViewScreenshotRecursive()
}
return
}
let guardTextField = UITextField()
guardTextField.backgroundColor = .red
guardTextField.translatesAutoresizingMaskIntoConstraints = false
guardTextField.tag = Int.max
guardTextField.isSecureTextEntry = true
addSubview(guardTextField)
guardTextField.isUserInteractionEnabled = false
sendSubviewToBack(guardTextField)
layer.superlayer?.addSublayer(guardTextField.layer)
guardTextField.layer.sublayers?.first?.addSublayer(layer)
guardTextField.centerYAnchor.constraint(
equalTo: self.centerYAnchor
).isActive = true
guardTextField.centerXAnchor.constraint(
equalTo: self.centerXAnchor
).isActive = true
}
}

Support

If you like then Buy me a coffee β˜•οΈ

Conclusion

Let me know if you have any questions, comments, or feedback – contact me on Twitter.

Stay Safe At Home. Learn Something New. Share To The World.
Happy Coding πŸ™‚

Did you know? How to hide keyboard in SwiftUI?

iOS 15 have new property wrapper: @FocusState. This is exactly like a regular @State property, except it’s specifically designed to handle input focus in our UI.

In this tutorial we will get to know that how to hide keyboard or you can say how to work with the @FocusState in SwiftUI.

Read more