Transport bar live label in AVPlayerViewController (tvOS only) - tvos

It seems impossible to disable or change the red backgrounded LIVE label in the AVPlayerViewController's transport bar on tvOS 15.2. Also, it is enabled by default ever since 15.2 came out. Here is a picture of the label shown here:
I have tried to play around with some of the available options like this one:
guard let pvc = playerRenderController as? AVPlayerViewController else { return }
pvc.transportBarIncludesTitleView = false
It does hide the LIVE label but it also hides the title (Straight Rhythm) from the image.
Furthermore, the label text seems to be specific to the locale, so in Danish it would be DIREKTE instead of LIVE.
Here is a video that showcases this feature (time 03:08):
Any suggestions on how to hide/change this label?

Hello I found a workaround to do it.
After you play the stream call this function with parameters the playerViewController.view
private func removeLiveLabel(view: UIView) {
let list = ["_AVPlayerViewControllerContainerView", "_AVFocusContainerView", "UIView"]
for subview in view.subviews where list.contains(String(describing: type(of: view))) {
for subSubview in subview.subviews {
if subSubview.value(forKey: "class").debugDescription.contains("_AVxOverlayPlaybackAuxiliaryMetadataView") {
subSubview.removeFromSuperview()
return
}
}
removeLiveLabel(view: subview)
}
}
This function will search the subviews of the AVPlayerViewController object controls and will remove the badge from the view without removing the Title.

Related

Adjusting the height of a wkwebview programmatically

This is my first question on Stack Overflow. I just started learning swift programming and got sucked into something.
I followed IAP tutorials on YouTube and successfully implemented AdMob banners and interstitial ads in my app. I was also able to turn off ads using the IAP. My question is:
I have a view in which I have two UI elements (WKWebViewand a GADBannerView). The WKWebView element covers 90% of the screen starting from x:0,y:0, whereas the GADBannerView element covers 10%. I turned off ads and hid the GADBannerView element using IAP.
Now I want to dynamically/programmatically adjust the WKWebView size to fill the entire screen, i.e 100%. In other words, I want the WKWebView element to extend over the hidden GADBannerView element.
This is because hiding the GADBannerView leaves a blank field which is not cool to the view and the WKWebView looks truncated.
Please note that neither of the views are subviews. Both are independent views added separately. I understand that I can initially make the web view fill entire screen, add the GADBannerView on top of it, and when I remove ads and hid the GADBannerView, the web view will fill screen. That is not what I want because some content of the web view can not be seen using this approach. If I have a button at the end of HTML page that loads on the web view, this button can not be clicked because it will always be behind the gad banner view even when scrolling reached the bottom. Yes, you can scroll and hold to see the button, but once you release it, it will go back down.
So as a recap, I have two separate views and want to hid one and extend the length of the other to cover the entire screen.
Please tell me how to achieve that.
thirdBannerView.isHidden = true //Hide the banner view
//then code below to increase the size of the web view to equal device //screen width and height i.e full screen.
func webViewDidFinishLoad(webView: WKWebView) {
//let screenBounds = UIScreen.main.bounds
// let heightq = screenBounds.height
//let widthq = screenBounds.width
//webView.frame.size.height = heightq
//webView.frame.size = webView.sizeThatFits(CGSize.zero)
//webView.frame = CGRectMake(0, 0, widthq, heightq);
webView.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
}
This code is not effective at all as nothing changes. Please let me know how to achieve this.
This particular scenario looks promising for applying UIStackview. Add your two view ( WKWebview and GADBannerView). apply fixed height for the GADBannerview. Whenever necessary just hide the GADBannerview.
Sample code
class StackviewController : UIViewController {
let stackview: UIStackView = {
let view = UIStackView()
view.axis = .vertical
view.distribution = .fill
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
// Your WKWebview here
let sampleWKWebView: UIView = {
let view = UIView()
view.backgroundColor = .red
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
// Your GADBannerView here
let sampleGADBannerView: UIView = {
let view = UIView()
view.backgroundColor = .green
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
setupViews()
}
func setupViews() {
view.addSubview(stackview)
stackview.addArrangedSubview(sampleWKWebView)
stackview.addArrangedSubview(sampleGADBannerView)
NSLayoutConstraint.activate([
stackview.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0.0),
stackview.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0.0),
stackview.topAnchor.constraint(equalTo: view.topAnchor, constant: 0.0),
stackview.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0.0),
sampleGADBannerView.heightAnchor.constraint(equalToConstant: 100.0)
])
// Enable this line to hide the GADBannerView
// sampleGADBannerView.isHidden = true
}
}
Here is the output
I use two UIView to represent the WKWebView & GADBannerView. In the sample code uncomment the following to hide the bottom banner like green view.
sampleGADBannerView.isHidden = true

swift: The HTML data converted to NSAttributed string doesn't make the links clickable in label

I have a text in HTML format. I am using the property of NSAttributed string to parse it. It pareses the text nicely and displays on the label. However, the parsing of the anchor tag doesn't make the link clickable. This is the following code that I am using for parsing.
extension String {
var htmlToAttributedString: NSAttributedString? {
guard let data = data(using: .utf8) else { return NSAttributedString() }
do {
return try NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding:String.Encoding.utf8.rawValue], documentAttributes: nil)
} catch {
return NSAttributedString()
}
}
var htmlToString: String {
return htmlToAttributedString?.string ?? ""
}
When I run the app and give the value to the label as:
text = "<p>This is Google Home</p>"
simpleTextLabel.attributedText = text.htmlToAttributedString
The output on the iOS App looks like following but nothing happens on clicking :
This is Google Home.
How can I make it open in safari?
From your line:
simpleTextLabel.attributedText = text.htmlToAttributedString
We can assume that simpleTextLabel is a UILabel.
It's basic behavior from a UILabel to not be "interactable". You can add a tap gesture on it, but it transform it as a UIButton.
There are some tricks to make it possible with a UILabel, find where exactly it has been tapped, check if there is a link, etc.
Looking for "UILabel Clickable": Create tap-able "links" in the NSAttributedString of a UILabel? etc. There are even a few third party libs.
I (in my humble opinion) consider it as a "hack".
There is a good WWDC 2018 Session: TextKit Best Practices. At 2:34, it explains that if you need to interact with a shown text, prefers UITextView over UILabel.
There is a UITextViewDelegate method just for that: textView(_:shouldInteractWith:in:interaction:)
Note that there a small differences in the rendering of a UITextView and a UILabel. If you superpose them, they won't have the same "start point", the layout is a little different. However, with small changes, it can be the same (for instance: How can I make a UITextView layout text the same as a UILabel?).
Note also that according to the small modifications of a UITextView into a UILabel visual rendering, the user won't notice the difference (and that's in fact what matters, beside that using native methods of the UITextView/UITextViewDelegate make it easily understandable afterwards by another developer, or in a few months if you need to do a small modification).

Google Maps AutoComplete dropdown hidden when Google Maps Full Screen is true

I've implemented a google maps with autocomplete onverlayed on the map and I've set the FullScreenControl option to "true" (You can see the FullScreenControl on the right in the image below)
My problem is that when I switch to FullScreen mode by clicking the FullScreenControl, the dropdown is hidden behind the google map.
It seems that the ZIndex is too low but setting it to a very large number does not seem to fix the issue. You can see from the image below that the dropdown exists, but only behind the fullscreen google map.
I did find a similar question with answer where someone used a normal dropdown and not the google map autocomplete.
Similar Question and answer
However the solution didn't work for me.
Setting the ZIndex doesn't seem to work.
I'm using TypeScript with Angular2.
Thank you.
]4
For anyone struggling with this, if the z-index solution is not working:
The Google maps generated div ("pac-container") with the autocomplete options is appended to the body child elements. But when in full screen, only elements inside the target element (the map div) will be shown, so z-index is ignored.
A quick workaround is to move the pac-container div inside the map div when entering full screen, and move it back on exit.
document.onfullscreenchange = function ( event ) {
let target = event.target;
let pacContainerElements = document.getElementsByClassName("pac-container");
if (pacContainerElements.length > 0) {
let pacContainer = document.getElementsByClassName("pac-container")[0];
if (pacContainer.parentElement === target) {
console.log("Exiting FULL SCREEN - moving pacContainer to body");
document.getElementsByTagName("body")[0].appendChild(pacContainer);
} else {
console.log("Entering FULL SCREEN - moving pacContainer to target element");
target.appendChild(pacContainer);
}
} else {
console.log("FULL SCREEN change - no pacContainer found");
}};
i was fix it with add z-index to .pac-container
see here
.pac-container, .pac-item{
z-index: 2147483647 !important;
}
Thank you #vladhorby! I ended up with your solution due to updating z-index not working on my case. I got 1 little bug, somehow that options position not in the right place when on the fullscreen mode. I add little code to fix this thing. The idea is to add a class when in fullscreen mode, and delete that after leave the fullscreen. Hope this can help anyone with the same case.
document.onfullscreenchange = function ( event ) {
let target = event.target;
let pacContainerElements = document.getElementsByClassName("pac-container");
if (pacContainerElements.length > 0) {
let pacContainer = document.getElementsByClassName("pac-container")[0];
if (pacContainer.parentElement === target) {
document.getElementsByTagName("body")[0].appendChild(pacContainer);
pacContainer.className += pacContainer.className.replace("fullscreen-pac-container", "");
} else {
target.appendChild(pacContainer);
pacContainer.className += " fullscreen-pac-container";
}
}
};
and the last thing add this to the your css file:
.fullscreen-pac-container[style]{
z-index: 2547483647 !important;
top:50px !important;
}

Change UISearchBar textColor not working

I am using google places API for autoComplete widget. I am showing the full screen control in ios 9+ using swift. I am adding a full control as given in the docs.
I have added the code as shown in the docs. Now I want to change the searchBar text color to whiteColor.
So I tried this
UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).textColor = UIColor.whiteColor()
But I am not getting the desired behaviour. Below is the screenshot
This has been given in Docs
https://developers.google.com/places/ios-api/autocomplete#use_a_table_data_source
But this is not working. I need help with regarding to this.
You need to create an extension like follwoing:
public extension UISearchBar {
public func setNewcolor(color: UIColor) {
let clrChange = subviews.flatMap { $0.subviews }
guard let sc = (clrChange.filter { $0 is UITextField }).first as? UITextField else { return }
sc.textColor = color
}
}
And change color using following code:
controller.searchBar.setNewcolor(UIColor.redColor())
Output is :
Update:
For the change color of searchBar text for the GMSAutocompleteViewController you need to do following code:
let searchBarTextAttributes: [String : AnyObject] = [NSForegroundColorAttributeName: UIColor.redColor(), NSFontAttributeName: UIFont.systemFontOfSize(UIFont.systemFontSize())]
UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).defaultTextAttributes = searchBarTextAttributes
That change the text out put like following image:
And if you wish to change placeholder text and it's color for searchBar. You need to do following code:
let placeholderAttributes: [String : AnyObject] = [NSForegroundColorAttributeName: UIColor.whiteColor(), NSFontAttributeName: UIFont.systemFontOfSize(UIFont.systemFontSize())]
let attributedPlaceholder: NSAttributedString = NSAttributedString(string: "Find a place", attributes: placeholderAttributes)
UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).attributedPlaceholder = attributedPlaceholder
It will be show like:
Use Bellow code for Swift 3
if #available(iOS 9.0, *) {
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSForegroundColorAttributeName: UIColor.green]
} else {
// Fallback on earlier versions
}
Hope this helps.
For swift 4 ios 12
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes
.updateValue(UIColor.white, forKey: NSAttributedStringKey.foregroundColor.rawValue)
You can use UIAppearance protocol to get the appearance proxy for a class which is available in iOS 5.0 and later.
There are actually two ways to customize appearance for objects and to get the appearance proxy for the class.
To customize the appearance of all instances of a class, use appearance.
To customize the appearances for instances of a class when contained within an instance of a container class, or instances in a hierarchy, use appearanceWhenContainedIn.
You can apply this sample code:
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:#{NSForegroundColorAttributeName:[UIColor redColor]}];
You can also try another option given in this SO post - UISearchBar text color change in iOS 7.
I hope that covers your issue. Happy coding!
In swift 5:
let searchBarTextAttributes: [NSAttributedString.Key : AnyObject] = [NSAttributedString.Key(rawValue: NSAttributedString.Key.foregroundColor.rawValue): UIColor.red, NSAttributedString.Key(rawValue: NSAttributedString.Key.font.rawValue): UIFont.systemFont(ofSize: 14.0)]
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = searchBarTextAttributes
This is actually very easy, just access the textField inside that searchBar as so:
searchBar.searchTextField.defaultTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red]
Lastest on swift 5
searchBar.searchTextField.textColor = .white

saving google map to image from a browser component window inside a c# application

I wanted to save the google map into an image from a webpage.
while i was searching for that i got this program.
http://www.codres.de/downloads/gms.exe[^]
besides other alternatives like print screen i wanted to use a program or map api which can save a specified dimension of google map instead of the screen.
i have used browser component in c# for http access and for displaying certain webpages.
I want to know whether there are options to capture the browser screen to image using any c# functionality or even the browser component would have given such options. just a guess.
i would like to have answers, suggestions on how to capture the map with custom dimension and zoom size to an image.
I used this to get captcha Image from the current page, so you can use similar code just amend the imageID to point to the google map image and use this solution for zooming.
public string newsavefunction(WebBrowser webBrowser1)
{
IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument;
IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();
string imagename = string.Empty;
try
{
foreach (IHTMLImgElement img in doc.images)
{
imgRange.add((IHTMLControlElement)img);
imgRange.execCommand("Copy", false, null);
using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
{
bmp.Save(#"F:\captchaimages\captchapic.jpg");
}
imagename = img.nameProp;
break;
}
}
catch (System.Exception exp)
{ }
return imagename;
}