BackgroundVideoiOS
  • September 18, 2023
This is an Object/Class which lets you add a background video to iOS app views. This is seen at login views of some famous apps like Spotify, tumbler and Vimeo
This is how they look..

Instructions for Swift:
  1. Have an awesome video that you want to show as your background

  2. Drag and drop BackgroundVideo.swift file to your Project navigator

  3. Drag and drop the video to your project and make sure to check Copy items if needed as well as Add to targets (This is because the object will look at your app’s main bunddle)

 

  1. Go to the view controller where you want to display the video and declare an instance.

var backgroundPlayer : BackgroundVideo? // Declare an instance of BackgroundVideo called backgroundPlayer

5. In your viewDidLoad() method, initialize your instance with the view controller you’re using and the name of the video file with it's extension as parameters (make sure you seperate your name and extension by a period). In the following code I’m passing the same view controller where I declared my instance, namely self. Then, just call the function setUpBackground() on your instance.

override func viewDidLoad() {
super.viewDidLoad()
// Initializing your instance
backgroundPlayer = BackgroundVideo(onViewController: self, withVideoURL: “test.mp4”) // Passing self and video name with extension
backgroundPlayer?.setUpBackground()
}

Instructions for Objective-C:
  1. Do steps 1-3 from the Swift steps above, but instead of dragging BackgroundVideo.swift, drag and drop BackgroundVideoObjC.h and BackgroundVideoObjC.m.

  2. Go to the view controller where you want to display the video and declare an instance.

@property (strong, nonatomic) BackgroundVideoObjC *backgroundVideo;

3. Same as 5 from Swift steps, except use this code:

– (void)viewDidLoad {
self.backgroundVideo = [[BackgroundVideoObjC alloc] initOnViewController:self withVideoURL:@”test.mp4″];
[self.backgroundVideo setUpBackground];
}

That’s it, you’re ready to go :)!

GitHub


View Github

YOU MIGHT ALSO LIKE...
PermissionsSwiftUI: A SwiftUI package to handle permissions

PermissionsSwiftUI displays and handles permissions in SwiftUI. It is largely inspired by SPPermissions. The UI is highly customizable and resembles an Apple style. ...

Pager tab strip view

Introduction PagerTabStripView is the first pager view built in pure SwiftUI. It provides a component to create interactive pager views ...

PageView

SwiftUI view enabling page-based navigation, imitating the behaviour of UIPageViewController in iOS.

Pages

    

How to take action when a property changes

1. Taking Action When a Property Changes: Property Observers Swift lets you observe and respond to changes in a property’s ...