how to toggle whole color of contents in my ios application programmatically? [closed] - ios

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 13 hours ago.
Improve this question
I want to implement a button that inverts the background color of the app when the user presses it. I tried assigning dark and light to the overrideUserInterfaceStyle property, but it only changes the color of the navigation bar. The only answers I've found so far are to create an ancestor controller of the full controller and manage the colors globally there. Can you tell me if there is a property or method that can access the full colors of the app? Or is there another good way...
here's my code I tried but only get feature toggles color of navigation bar dark/light...
#objc func onClickSwitch(_ sender : UISwitch) {
if #available(iOS 13.0, *) {
let windowScene = UIApplication.shared.connectedScenes.first as! UIWindowScene
if sender.isOn {
print("dark mode")
windowScene.keyWindow?.overrideUserInterfaceStyle = .dark
} else {
print("white mode")
windowScene.keyWindow?.overrideUserInterfaceStyle = .light
}
}
}

Related

Add tools with GIF background (Swift) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I already typed codes for some tools(text/button/label), but once i put a gif background they disappeared. the question is .. How to get them into the foreground?
override func viewDidLoad() {
let filePath = NSBundle.mainBundle().pathForResource("tiger", ofType: "gif")
let gif = NSData(contentsOfFile: filePath!)
let webViewBG = UIWebView(frame: self.view.frame)
webViewBG.loadData(gif!, MIMEType: "image/gif", textEncodingName: String(), baseURL: NSURL())
webViewBG.userInteractionEnabled = false;
self.view.addSubview(webViewBG)
}
Looking at your code I'd say that when you call addSubview method, the view you are adding is on the foreground.
You have to call one of these methods to manipulate view hierarchy :
view.sendSubviewToBack(view: UIView)
view.bringSubviewToFront(view: UIView)
What I'd do is to add the subview, then send it to the background with sendSubviewToBack method
UPDATE :
Seems that it doesn't work that way. There will be several solutions you could use. Either you keep your web view and your view separated but with the same frame so that your view is just on top of your web view.
Problem is that if your frame changes, you have to change the frames of both views.
Another solution is to add your label inside your web view (didn't test it though but it works with an image view so I assume it may work).

UITextField text disappearing while typing [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Strange behaviour observed on UITextField text disappears,
Steps:
Type text in UITextField and click home button.
Open another application (App) and click home button.
Then Open First App the UITextField in text is disappears.
Issue observed in IPhone 6s version 9.2.1. but perfectly working in simulator.
You can override this method in your custom responders to update your object's state or perform some action such as highlighting the selection. If you override this method, you must call super at some point in your implementation.
The custom Class should be similar to:
class CustomSecureTextField: UITextField {
override func becomeFirstResponder() -> Bool {
super.becomeFirstResponder()
//if !isSecureTextEntry {
// return true
//}
if let currentText = text {
insertText(currentText)
}
return true
}
}

Can not stop music when back to first view controller [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I've build a second view controller for a radio app to send text's to the radiostation. So, when i press play on the first view controller it play's the stream and you can check what's playing now and coming up. I've made a button to the second view controller, the music is still playing, that's good! But i can't stop it in ControlCenter and when i go back to the first view controller the button is back to "Play" and not "Stop" in the app.
Seems like the first view controller is getting a "reset?" when you go to the second view controller. How can i fix this?
Image: http://imgur.com/wZtAyz6
Dennis
You can also declare your audioPlayer in the appDelegate :
// inside AppDelegate
var ap : AVAudioPlayer? = nil
then simply declare in your viewController :
var ap : AVAudioPlayer? {
get {
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
return appDelegate.ap
}
set {
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.ap = newValue
}
}

Implement Objective C code in Swift [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to handle the pressing of the back button on a UI Navigation bar. I have an extension in objective C (https://github.com/onegray/UIViewController-BackButtonHandler) and i have bridged it to my project in Swift using the header, now I do not quite know how to implement the code in Swift. This is the implementation in C:
-(BOOL) navigationShouldPopOnBackButton {
if(needsShowConfirmation) {
// Show confirmation alert
// ...
return NO; // Ignore 'Back' button this time
}
return YES; // Process 'Back' button click and Pop view controler
}
func navigationShouldPopOnBackButton() -> Bool {
if(needsShowConfirmation) {
// Show confirmation alert
// ...
return false // Ignore 'Back' button this time
}
return true // Process 'Back' button click and Pop view controller
}

NSNotification for UIAlertController [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is there an option to observe and get the information about appearing and disappearing?
I want to grayscale my elements like apple ui-elements by appearing of UIAlertController!
Since now i found out that the "_UIBackdropViewComputeAndApplySettingsNotification" was called and contains userInfo about the appearing view.
You are going to make the UIAlertController's view appear, so how can you not know? You don't need to observe it; you're doing it (by calling presentViewController...).
That takes of what happens when the alert appears. What about when it disappears? Well, it disappears because the user tapped a button. You get to write the handler for every button in the alert. So again, you know when the alert is disappearing, because your handler is running.
The solution is, everything works automatically. You just have to implement..
override func tintColorDidChange() {
self.setNeedsDisplay()
}
..and of course working with the tintColor
Thanks matt for quick answer!
To expand on the other answers: each of your UIView subclasses should implement tintColorDidChange to be notified of the change.
Here's a sample implementation:
class someLabel : UILabel {
override func tintColorDidChange() {
let isInactive = self.tintAdjustmentMode == UIViewTintAdjustmentMode.Dimmed
if (isInactive) {
// modify subviews to look disabled
self.textColor = UIColor.grayColor()
} else {
// modify subviews to look enabled
self.textColor = self.tintColor
}
}
}
A few other good code samples (albeit in Objective-C) can be found in this SO question.

Resources