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).
Related
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
}
}
}
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 5 years ago.
Improve this question
I have a UICollectionView with 4 Cells, I have a controller for those 4 pages called SwipingController.
I'd like to have a UIViewController for each cell, how can I achieve that ?
I counter advise on what you are going for.
Better just to have Views that manage their layout you don't need controllers to manage layout.
I don't think you will be able to hold a familiar architecture (MVC/MVVM/MVP/VIPER .. ) in the future if you go in this direction.
Also check this out. It will help you understand better the role of a view controller.
Nonetheless you can achieve this with addChildViewController(documentation here)
Add child view
let controller = storyboard?.instantiateViewController(withIdentifier: "test") as! UIViewController
self.addChildViewController(controller)
controller.view.frame = CGRect(0, 44, 320, 320)
self.view.addSubview(controller.view)
controller.didMove(toParentViewController: self)
Remove child view
let vc = self.childViewControllers.last
vc.removeFromSuperview()
vc.willMove(toParentViewController: nil);
vc.removeFromParentViewController()
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 5 years ago.
Improve this question
I am trying to make a UIImageView named rDot tappable with tapGesture. When the image view rDot is tapped I want a different UIImageView on a different viewController, named wCircle to turn red. The problem is the code runs, but when I tap rDot the other image wCircle doesn't turn red.
override func viewDidLoad() {
super.viewDidLoad()
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(imageTapped(tapGestureRecognizer:)))
rDot.isUserInteractionEnabled = true
rDot.addGestureRecognizer(tapGestureRecognizer)
}
func imageTapped(tapGestureRecognizer: UITapGestureRecognizer)
{
let wCircle = UIImageView(image: UIImage(named:"wCircle")?.withRenderingMode(.alwaysTemplate)) //error here
wCircle.tintColor = UIColor.red
}
In the context of Swift code, EXC_BAD_INSTRUCTION usually means you’ve hit a compiler trap, that is, an undefined instruction inserted into the code by the compiler because of a bug detected at runtime. The most common cause of these are:
failure to unwrap an optional — This can be a forced unwrap (!) or an implicit unwrap (accessing an implicitly unwrapped optional that’s nil).
array out of bounds
a failed forced cast (as!), either because the value was a nil optional or because the value was of the wrong type.
Check if wCircle is not nil.
Check if the outlet is properly connected.
make sure your image assets has an image exactly named "wCircle" case sensitive ,
again, in assets not in project bundle , i think UIImageView couldn't be initialized because an image with "wCircle" does not exist in assets
The way you init your UITapGestureRecognizer is incorrect.
Try
UITapGestureRecognizer(target: self, action: #selector(ViewController.imageTapped(tapGestureRecognizer:)))
Replace ViewController with your controller's class name
Make sure your object wCircle is present and initialize successfully
What is "wCircle" ? UIImage has no property called tintColor, if you want change image's color change his container UIImageView's tintColor
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
}
}
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.