Change all UIViewControllers Backgrounds
I want to change all my project's UIViewControllers, so I have this:
let bg = BackgroundImage().backgroundImage
bg.alpha = 0.2
bg.frame = self.view.frame
let wBg = UIView()
wBg.frame = self.view.frame
wBg.backgroundColor = UIColor(white: 1, alpha: 0.5)
self.view.addSubview(wBg)
self.view.sendSubview(toBack: wBg)
self.view.addSubview(bg)
self.view.sendSubview(toBack: bg)
Where BackgroundImage().backgroundImage
returns a UIImageView.
But how can I implement this on all my UIViewControllers without having to copy/paste the same in all my VC.
ios swift
add a comment |
I want to change all my project's UIViewControllers, so I have this:
let bg = BackgroundImage().backgroundImage
bg.alpha = 0.2
bg.frame = self.view.frame
let wBg = UIView()
wBg.frame = self.view.frame
wBg.backgroundColor = UIColor(white: 1, alpha: 0.5)
self.view.addSubview(wBg)
self.view.sendSubview(toBack: wBg)
self.view.addSubview(bg)
self.view.sendSubview(toBack: bg)
Where BackgroundImage().backgroundImage
returns a UIImageView.
But how can I implement this on all my UIViewControllers without having to copy/paste the same in all my VC.
ios swift
add a comment |
I want to change all my project's UIViewControllers, so I have this:
let bg = BackgroundImage().backgroundImage
bg.alpha = 0.2
bg.frame = self.view.frame
let wBg = UIView()
wBg.frame = self.view.frame
wBg.backgroundColor = UIColor(white: 1, alpha: 0.5)
self.view.addSubview(wBg)
self.view.sendSubview(toBack: wBg)
self.view.addSubview(bg)
self.view.sendSubview(toBack: bg)
Where BackgroundImage().backgroundImage
returns a UIImageView.
But how can I implement this on all my UIViewControllers without having to copy/paste the same in all my VC.
ios swift
I want to change all my project's UIViewControllers, so I have this:
let bg = BackgroundImage().backgroundImage
bg.alpha = 0.2
bg.frame = self.view.frame
let wBg = UIView()
wBg.frame = self.view.frame
wBg.backgroundColor = UIColor(white: 1, alpha: 0.5)
self.view.addSubview(wBg)
self.view.sendSubview(toBack: wBg)
self.view.addSubview(bg)
self.view.sendSubview(toBack: bg)
Where BackgroundImage().backgroundImage
returns a UIImageView.
But how can I implement this on all my UIViewControllers without having to copy/paste the same in all my VC.
ios swift
ios swift
edited Nov 13 '18 at 0:16
rmaddy
239k27311376
239k27311376
asked Nov 13 '18 at 0:13
Cesar RodriguezCesar Rodriguez
689
689
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
One solution is to create a function in a UIViewController
extension. This function should setup the view controller's background as needed.
Then in the viewDidLoad
function of each of your view controllers you can call that extension function.
1
GREAT! I created anBgImage+UIViewcontroller.swift
extension then created the function setBackgroundImage() and done! Thanks @rmaddy!
– Cesar Rodriguez
Nov 13 '18 at 0:41
add a comment |
1. Create BaseViewController.swift
class BaseViewController: UIViewController
override func viewDidLoad()
setBackgroundImage()
setBackgroundImage()
2. Other ViewController will inherit the BaseViewController
class TimelinesViewController: BaseViewController
1
The problem with this solution is that it doesn't work for table view controllers and collection view controllers and others.
– rmaddy
Nov 13 '18 at 3:06
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271959%2fchange-all-uiviewcontrollers-backgrounds%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
One solution is to create a function in a UIViewController
extension. This function should setup the view controller's background as needed.
Then in the viewDidLoad
function of each of your view controllers you can call that extension function.
1
GREAT! I created anBgImage+UIViewcontroller.swift
extension then created the function setBackgroundImage() and done! Thanks @rmaddy!
– Cesar Rodriguez
Nov 13 '18 at 0:41
add a comment |
One solution is to create a function in a UIViewController
extension. This function should setup the view controller's background as needed.
Then in the viewDidLoad
function of each of your view controllers you can call that extension function.
1
GREAT! I created anBgImage+UIViewcontroller.swift
extension then created the function setBackgroundImage() and done! Thanks @rmaddy!
– Cesar Rodriguez
Nov 13 '18 at 0:41
add a comment |
One solution is to create a function in a UIViewController
extension. This function should setup the view controller's background as needed.
Then in the viewDidLoad
function of each of your view controllers you can call that extension function.
One solution is to create a function in a UIViewController
extension. This function should setup the view controller's background as needed.
Then in the viewDidLoad
function of each of your view controllers you can call that extension function.
answered Nov 13 '18 at 0:29
rmaddyrmaddy
239k27311376
239k27311376
1
GREAT! I created anBgImage+UIViewcontroller.swift
extension then created the function setBackgroundImage() and done! Thanks @rmaddy!
– Cesar Rodriguez
Nov 13 '18 at 0:41
add a comment |
1
GREAT! I created anBgImage+UIViewcontroller.swift
extension then created the function setBackgroundImage() and done! Thanks @rmaddy!
– Cesar Rodriguez
Nov 13 '18 at 0:41
1
1
GREAT! I created an
BgImage+UIViewcontroller.swift
extension then created the function setBackgroundImage() and done! Thanks @rmaddy!– Cesar Rodriguez
Nov 13 '18 at 0:41
GREAT! I created an
BgImage+UIViewcontroller.swift
extension then created the function setBackgroundImage() and done! Thanks @rmaddy!– Cesar Rodriguez
Nov 13 '18 at 0:41
add a comment |
1. Create BaseViewController.swift
class BaseViewController: UIViewController
override func viewDidLoad()
setBackgroundImage()
setBackgroundImage()
2. Other ViewController will inherit the BaseViewController
class TimelinesViewController: BaseViewController
1
The problem with this solution is that it doesn't work for table view controllers and collection view controllers and others.
– rmaddy
Nov 13 '18 at 3:06
add a comment |
1. Create BaseViewController.swift
class BaseViewController: UIViewController
override func viewDidLoad()
setBackgroundImage()
setBackgroundImage()
2. Other ViewController will inherit the BaseViewController
class TimelinesViewController: BaseViewController
1
The problem with this solution is that it doesn't work for table view controllers and collection view controllers and others.
– rmaddy
Nov 13 '18 at 3:06
add a comment |
1. Create BaseViewController.swift
class BaseViewController: UIViewController
override func viewDidLoad()
setBackgroundImage()
setBackgroundImage()
2. Other ViewController will inherit the BaseViewController
class TimelinesViewController: BaseViewController
1. Create BaseViewController.swift
class BaseViewController: UIViewController
override func viewDidLoad()
setBackgroundImage()
setBackgroundImage()
2. Other ViewController will inherit the BaseViewController
class TimelinesViewController: BaseViewController
answered Nov 13 '18 at 2:00
GiangGiang
1,3041214
1,3041214
1
The problem with this solution is that it doesn't work for table view controllers and collection view controllers and others.
– rmaddy
Nov 13 '18 at 3:06
add a comment |
1
The problem with this solution is that it doesn't work for table view controllers and collection view controllers and others.
– rmaddy
Nov 13 '18 at 3:06
1
1
The problem with this solution is that it doesn't work for table view controllers and collection view controllers and others.
– rmaddy
Nov 13 '18 at 3:06
The problem with this solution is that it doesn't work for table view controllers and collection view controllers and others.
– rmaddy
Nov 13 '18 at 3:06
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271959%2fchange-all-uiviewcontrollers-backgrounds%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown