How to style GCKUIMiniMediaControlsViewController in iOS? - ios

I'm upgrading current Cast SDK to V3 and want to use build-in UI components and remove deprecated functions.
Currently, the GCKUIMiniMediaControlsViewController has a white/light theme but I'd like to change it to a darker theme. However, I couldn't find any function/propert/protocol that I can use to change the style. The document Add Advanced Cast v3 Features to your iOS App says:
The Cast framework widgets supports the Apple UIAppearance Protocol in
UIKit to change the appearance of the widgets across your app, such as
the position or border of a button. Use this protocol to style the
Cast framework widgets to match an existing apps styling.
This makes me feel like I can change the appearance but I'm not quite sure what does The Cast framework widgets supports the Apple UIAppearance Protocol in UIKit mean :(
I also find a previous question which also related to Cast SDK's UI component. How can I get access to Introductory Overlay?
Can anyone help me how to change the style for GCKUIMiniMediaControlsViewController?

Cast SDK v3 for iOS introduced GCKUIStyle.
This makes styling of all cast views very easy (which includes mini controller, expanded controller, etc). As it contains pretty much all properties for customization.
For GCKUIMiniMediaControlsViewController specifically
GCKUIStyle *castStyle = [GCKUIStyle sharedInstance];
// customize Mini Controller
GCKUIStyleAttributesMiniController *miniCtrlStyle = [[[castStyle castViews] mediaControl] miniController];
[miniCtrlStyle setBackgroundColor:backColor];
[miniCtrlStyle setIconTintColor:[UIColor whiteColor]];
[miniCtrlStyle setHeadingTextColor:[UIColor whiteColor]];
[castStyle applyStyle];

https://developer.apple.com/reference/uikit/uiappearance
For example if you want to change the background color of every UILabel that is contained in GCKUIExpandedMediaControlsViewController.
ex in Swift:
UILabel.appearance(whenContainedInInstancesOf:[GCKUIExpandedMediaControlsViewController.self]).backgroundColor = URColors.URStrawberryRed

You need to follow Apple's instructions on using the UIAppearance protocol. Note that any changes you make to the styling will happen across the entire app.

Related

How can i make customizable views on IOS ? (i used style.id as a parameter on android view class constructor)

First I want to talk about what I exactly did on Android, and I am now trying to do the same on IOS :
I developed a library on Android which contains an activity, in that activity we have several type of views (labels, buttons ... etc).
These views are used as an entry point/inputs for my library that provides some services to other apps.
To be able to match the general style of the user app, I created my own View Classes, the user(of my library) needs to provide a style id to the activity before launching it, so it can be used when constructing the View.
Doing so, we are able to maintain the style of the app without the need to re-implement the views for every app that uses my library or making the user(final user on physical device) feels as if he just moved out to another app.
I am really a newbie on iOS and I recently started to learn it so i am not sure how to do it, can you please provide me some guidelines please?
On iOS there are so many ways to create views (xibs, Storyboards , SwiftUI, and programatically). I am not really sure where to start.
He's a sample of my code on Android :
class MyView(val context: Context, val themeId: Int) : View(context) {
init {
val wrappedContext = ContextThemeWrapper(context, themeId)
val mInflater = wrappedContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
mInflater.inflate(R.layout.my_view_layout, this, true)
}
}
This is a very broad question, but the short answer is "sure, it can be done."
I suppose a quick example might be:
I have a custom UIView with a UILabel centered in it, with 20-pts padding on all 4 sides.
I have 4 "themes" defined, defining the view's background color, the label's text color and the label's font style.
I write a custom init func to accept an Int "id" of 1 through 4
The library user could then instantiate it along the lines of let myView = MyView(with themeId: 2)
As this is a very broad question (topic), once you start developing your custom view you could come back if you run into specific coding questions.

What type of UI component is this?

I see this type of action sheet on iOS devices using the Google Drive application.
I want to know if it is already supported on iOS SDK or if it is a custom UI?
If it is already a standard component, what's name of it?
It was called UIActionSheet before iOS8 and after you can find this UI component under the UIAlerController. You can use this component to make some UI like this but development target should be more that iOS8.
You can check here for documentation.
I'm not aware of any custom components, but it looks to me like a standard UIAlertController with a ActionSheet style. As the alert controller extends UIViewController, you may add subviews to it.
The screenshots indicate that they added a UITableView as a subview to the alert controller:
Ok, got it. It's only for iOS 8 and later. It's named UIDocumentPickerExtensionViewController.

Is there a way to check if "increase contrast" is enabled in the accessibility settings in iOS?

On iOS 7.0.3 turning on increased contrast mode removes the blur effects you'd normally see in the nav bar if you're using a bar tint color with an alpha less than 1.0, which makes the nav bar seem much more transparent than it is with the default settings.
Is there a way to programmatically check to see if this setting is enabled? While UIAccessibility has a ton of other functions like UIAccessibilityIsInvertColorsEnabled(), I can't find anything related to this setting specifically.
As of iOS 8 there is a way to check:
UIKIT_EXTERN BOOL UIAccessibilityDarkerSystemColorsEnabled() NS_AVAILABLE_IOS(8_0);
as of modern iOS:
UIAccessibility.isDarkerSystemColorsEnabled
Apparently there's no public API for checking whether that option is on.
According to the UIKit Function Reference, the only checks you can perform are the following
UIAccessibilityPostNotification
UIAccessibilityIsVoiceOverRunning
UIAccessibilityIsClosedCaptioningEnabled
UIAccessibilityRequestGuidedAccessSession
UIAccessibilityIsGuidedAccessEnabled
UIAccessibilityIsInvertColorsEnabled
UIAccessibilityIsMonoAudioEnabled
UIAccessibilityZoomFocusChanged
UIAccessibilityRegisterGestureConflictWithZoom
UIAccessibilityConvertFrameToScreenCoordinates
UIAccessibilityConvertPathToScreenCoordinates
For iOS 13 and above we can use accessibilityContrast
Documentation
Use this trait to determine whether the user requested a high contrast
between foreground and background content. The user sets the contrast
level in the Accessibility area in Settings.
Apple doc link

How to include skins in ios app

I developed a new iPad calculator and am working on an update for it that has a settings option where you can change the app's skin. Currently, I am using different UIViewControllers for that, but it is not the best solution.
To build on #MJN's answer, once you have selected a skin/theme class, you can easily apply it across your app using UIAppearance, which lets you set styles for all instances of common UIKit classes like UIButton, UIBarButtonItem, UINavigationBar, etc.
You can make an AppSkinProtocol that has methods like the following
- (NSString*)skinIdentifier;
- (UIColor*)highlightedButtonColor;
- (UIImage*)successfulDownloadAlertBackground;
Then make subclasses of NSObject that conform to your AppSkinProtocol.
You can then make a AppSkinManager to save the selected skin to NSUserDefaults. When the app launches load the skin with the identifier matching the string saved to defaults.

How to create a theme based application?

I know similar question is already asked, but didn't get a satisfactory answer. So i am adding this question again .
Based on user selection in iphone application , i need to change the look and feel of the application (color font background images etc ). Is there any standard way to achieve this ?
one possible solution can be duplicating xib files for each theme and loading it based on selection. Is this a good approach? mainly because wiring the outlets and actions for xib copies sounds to be a redundant task.
I would like to see expert suggestion for this doubt.
Thanks for any help in advance.
-mia
For the non-XIB route
Color: iOS 5 exposes the new appearance APIs. Most UI elements have the option if setting a tintColor or a backgroundColor. Rarely, even a background image.
Font: Was always able to change, but you couldn't animate it.
Background image: Your main UIView should have the option for a background image, or if that fails, a background color with a pattern image.
As CodaFI said, if you are using iOS 5 or greater, you already have a theming feature. It works like this:
Add the protocol <IAppearanceContainer> to the class.
Decorate the property you intend to change with UI_APPEARANCE_SELECTOR. Example:
#interface UINavigationBar : ... <IAppearanceContainer>
#property(nonatomic,retain) UIColor *tintColor UI_APPEARANCE_SELECTOR;
#end
Change the color for all instances of the class:
[[UINavigationBar appearance] setTintColor:[UIColor redColor]];
The example above is the UINavigationBar, but it would work with any custom class. To see the objects already supported in iOS 6.1, check the documentation or run the following commands:
cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/UIKit.framework/Headers
grep -H UI_APPEARANCE_SELECTOR ./* | sed 's/ __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;//'
Let's say you want modular themes:
Write a big plist file with all the fonts, colors, music, and what not. Each of these files will be a theme.
Read the file through a singleton and set the values with lines like [x appearance] setWhatever:<plist value>] for each theme-able element.
If you have instances of the same element that need to display different elements, get those images through the singleton.
That is more or less the tip from Amit Vyawahare. I said plist instead xml because they are easier to read. Don't duplicate the NIBs unless you really have to.
Best way to implement theme based application IOS application (not using ~xib route). you should create a build.xml file which will content all the pieces of themes. You should keep your layout same and you can change images, style, fonts, lang, views, in that layout according to users pref. By doing this you are not duplicating any code and you will achieve best performances from your application.

Resources