Custom like button IOS SDK - ios

it is possible to customize the facebook like button SDK? I need my turn Button image or set the background of the button as image
var likeControl:FBSDKLikeControl = FBSDKLikeControl()
likeControl.objectID = fbPage
likeControl.likeControlStyle = FBSDKLikeControlStyle.BoxCount
likeControl.backgroundColor = UIColor(patternImage: UIImage(named: "fblike")!)
likeControl.frame = CGRectMake(16,20, 290, 40)
self.viewBotoes.addSubview(likeControl)

You can't assign your own background image to the FBSDKLikeControl, which is inherited from the UIControl
FBSDKLikeControl is exposing only a few properties such as foregroundColor, FBSDKLikeControlAuxiliaryPosition, FBSDKLikeControlHorizontalAlignment, likeControlStyle, preferredMaxLayoutWidth and soundEnabled

Related

AVRoutePickerView Won't Change Color when Airplay is Active

I have a AVRoutePickerView in a ViewController that I can't get to change color when it's using Airplay.
AVRoutePickerView *routePickerView = [AVRoutePickerView new];
routePickerView.backgroundColor = [UIColor clearColor];
routePickerView.activeTintColor = [UIColor blueColor];
routePickerView.tintColor = [UIColor whiteColor];
//I put it in a StackView, incidentally
[self.bottomButtonStack insertArrangedSubview:routePickerView atIndex: 3];
[routePickerView.layer setFrame:CGRectMake(80,80,80,80)];
[routePickerView.heightAnchor constraintEqualToConstant:52].active = true;
[routePickerView.widthAnchor constraintEqualToConstant:52].active = true;
This works fine, but the button always stays the tintColor even when an AirPlay source is being used from the picker.
How do I get the button to change to the activeTintColor when Airplay is active?
I thought it was automatically supposed to use the activeTintColor when Airplay was active. If no colors are set, the color of the button is always blue no matter what.
Thanks in advance!
I first noticed this problem after upgrading to iOS 12.3. I have since discovered that creating an instance of AVRouteDetector causes AVRoutePickerView to correctly apply the activeTintColor. Just create the detector and retain in a member variable:
self.myDetector = AVRouteDetector()
// create route picker view as usual
you need set routePickerButtonStyle
let routePickerView = AVRoutePickerView(frame: CGRect(x: 200, y: 200, width: 100, height: 100))
routePickerView.routePickerButtonStyle = .custom
routePickerView.backgroundColor = UIColor.clear
routePickerView.delegate = self
self.view.addSubview(routePickerView)

Can I change the background color of the Chromecast navigation bar?

I've reviewed the custom styles available in the GoogleCast v3 SDK and unless I'm missing something I don't see a way to change the backgroundColor of the deviceChooser. See below:
Is there any way to change this gray color?
As per the documentation Google does not allow us to change the navigation bar style. So we might need to change the navigation bar appearance before pushing to the media control UI of SDK.
I tried it in didFinishLaunchingWithOptions
[UINavigationBar appearance].barTintColor = [UIColor whiteColor];
[UINavigationBar appearance].translucent = NO;
Hope it helps :)
There are different ways you can customize the style on Chromecast SDK for iOS by using:
GCKUIStyle.sharedInstance()
My contribution for style the navigation bar:
From DOCUMENTATION I can see the following diagram
The common thing between all the "Style class" is that all of them inherit from GCKUIStyleAttributes so:
func configureChromecast() {
let gckCriteria = GCKDiscoveryCriteria(applicationID: "ABC123")
let gckCastOptions = GCKCastOptions(discoveryCriteria: gckCriteria)
GCKCastContext.setSharedInstanceWith(gckCastOptions)
GCKLogger.sharedInstance().delegate = self
// General
let textColor: UIColor = UIColor.black
let backgroundColor: UIColor = UIColor.white
GCKUIStyle.sharedInstance().castViews.backgroundColor = backgroundColor
GCKUIStyle.sharedInstance().castViews.headingTextColor = textColor
GCKUIStyle.sharedInstance().castViews.headingTextFont = UIFont.textStyleRegular
GCKUIStyle.sharedInstance().castViews.bodyTextColor = textColor
GCKUIStyle.sharedInstance().castViews.bodyTextFont = UIFont.textStyleRegular
GCKUIStyle.sharedInstance().castViews.captionTextColor = textColor
GCKUIStyle.sharedInstance().castViews.captionTextFont = UIFont.textStyleRegular
GCKUIStyle.sharedInstance().castViews.buttonTextColor = textColor
GCKUIStyle.sharedInstance().castViews.buttonTextFont = UIFont.textStyleRegular
GCKUIStyle.sharedInstance().castViews.iconTintColor = textColor
// Navigation & Toolbar
let navigationBackgroundColor: UIColor = UIColor.blue
let navigationtintColor: UIColor = UIColor.white
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.backgroundColor = navigationBackgroundColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.backgroundColor = navigationBackgroundColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.headingTextColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.headingTextColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.bodyTextColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.bodyTextColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.captionTextColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.captionTextColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.buttonTextColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.buttonTextColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.iconTintColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.iconTintColor = navigationtintColor
GCKUIStyle.sharedInstance().apply()
}
And the result:
The Navigation Bar style in question doesn't come from GoogleCast SDK (at least for version 4.6.1 dynamic on iOS 15) but from your own app's appearance. A way to change the background and title text color of the Navigation Bar (on GoogleCast SDK View Controllers, but your own app's as well) is to add
UINavigationBar.appearance().backgroundColor = UIColor.darkGray
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
in your AppDelegate's didFinishLaunchingWithOptions function.
But, no matter what tint color field I try setting for either UINavigationBar or UIBarButtonItem appearance, I can't get the Cancel button text color to change. I noticed that behavior in my app as well, only the Navigation Bar Buttons that have the tint set as Default in the Storyboard are affected by this global change, specifically by setting
UIBarButtonItem.appearance().tintColor = UIColor.yellow
If on the other hand you set a color in the Storyboard yourself, it will not be changed by the line of code above. This conclusion leads me to believe that is the way the Device Chooser View Controller was created, with a tint color set explicitly.
But, I see in one of the comments to the main question that someone was able to change the Cancel button color (as seen in the screenshot as well), so if anyone can share that piece of code it would be extremely appreciated.
Thanks!
EDIT
And of course only after posting this I tried pasting the entire code snippet from Reimond Hill and it worked in changing the Cancel button color, specifically this
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.buttonTextColor = navigationtintColor
The reason why I thought this wouldn't work first time around is the fact that we are setting the navigation property of the Connection Controller, not the Device Controller (which doesn't even have this property). So I hope this will help someone else not waste time on this like I did.
You can style all GCK views using GCKUIStyle,
for example:
GCKUIStyle.sharedInstance().castViews.mediaControl.miniController.buttonTextColor = .black
GCKUIStyle.sharedInstance().apply()
in your case, the navigation can be styled with this line
connectionController.navigation.backgroundColor = UIColor.black
Check this URL for more info:
https://developers.google.com/cast/docs/ios_sender/customize_ui

How to set button background image size

I want to create this button in my application. I have added a button to my view in storyboard. Set it's width and height constraints to 60px.
Then in code I've added corner radius and UIImage to background but the image filled the whole button background. The image is 22x22px. I want it to be centered in button like on my screenshot.
var pencilImage = UIImage(named: "pencil")!
pencilBtn.setBackgroundImage(pencilImage, forState: UIControlState.Normal)
pencilBtn.layer.cornerRadius = pencilBtn.frame.size.height / 2
pencilBtn.clipsToBounds = true
What should I code to solve this?
Set image using .setImage() method Like this:
pencilBtn.layer.cornerRadius = pencilBtn.frame.size.height / 2
pencilBtn.clipsToBounds = true
pencilBtn.setImage(UIImage("pencil"), forState: .Normal)
pencilBtn.contentMode = UIViewContentMode.Center

Can't display image in custom keyboard

i'm building custom keyboard for ios 8, so i want to display one image here but it's seems not work.
I really don't know why, here is my code:
var img = UIImageView()
img.frame = CGRectMake(0, 0, 50, 50)
img.image = UIImage(named: "interesting.jpg")
self.view.addSubview(img)
Nothing appear but if i change to display an UILabel, it's ok.
When i move this code to ViewController image display fine.
I couldn't display image in keyboard area only.
I think you could do this: UIImage(named: "interesting") and have the name of the image in the asset catalog be interesting

Change Color of MPVolumeView Route Button iOS 7

I am designing a Music app for iOS 7 and I want to put the "AirPlay" route selector button directly in my app. I am able to get the button placed just fine, however it doesn't show up because the icon is white and my background is white.
Is there a way to change the color of the Route Button?
Here is the code I'm using to create the button.
self.airPlayButton = [[MPVolumeView alloc] initWithFrame:CGRectZero];
self.airPlayButton.showsVolumeSlider = NO;
[self.airPlayButton sizeToFit];
self.airPlayButton.backgroundColor = [UIColor myGreenColor];
[self addSubview:self.airPlayButton];
Basically the picture below is what I want, except I want the icon green instead of just it's background.
in reviewing Adams answer I like more clarity in that task. So I safe-guarded that code a bit:
Objective-C:
for( UIView *wnd in volumeView.subviews ) {
if( [wnd isKindOfClass:[UIButton class] ]) {
UIButton *button = (UIButton*) wnd;
UIImage *img = button.currentImage;
UIImage *img2 = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[volumeView setRouteButtonImage: img2 forState:UIControlStateNormal];
break;
}
}
Swift:
for view in volumeView.subviews {
if view.isKindOfClass(UIButton) {
let buttonOnVolumeView : UIButton = view as! UIButton
volumeView.setRouteButtonImage(buttonOnVolumeView.currentImage?.imageWithRenderingMode(.AlwaysTemplate), forState: .Normal)
break;
}
}
Now it reacts on the tintColor property of volumeView and if Apple decides to add another button or change the sequence this code will still work.
To expand on lanbo's answer, you can also get the original image of the Route Button and create a copy that uses the UIImageRenderingMode.AlwaysTemplate rendering mode. That way it heeds the current tintColor.
In Swift:
let volumeView = MPVolumeView()
if let routeButton = volumeView.subviews.last as? UIButton,
let routeButtonTemplateImage = routeButton.currentImage?.imageWithRenderingMode(.AlwaysTemplate)
{
volumeView.setRouteButtonImage(routeButtonTemplateImage, forState: .Normal)
}
Create your own image and Try
setRouteButtonImage:forState:
Assigns a button image to the specified control states.
- (void)setRouteButtonImage:(UIImage *)image forState:(UIControlState)state
Parameters
image - The image to associate with the specified states.
state - The control state with which to associate the image.
Discussion
Use this to customize the appearance of the route button when it is enabled, disabled, highlighted, and so on.
Available in iOS 6.0 and later.

Resources