How to change apple watch interface controller title size/text? - apple-watch

How to change apple watch interface controller title size/text ?
Can we provide custom fonts ?
Tries with setting title programmatically using NSAttributedText but no success.
Any ideas ?

You can change the interface controller's title by calling:
swift : func setTitle(_ title: String?)
objc: - (void)setTitle:(NSString *)title
For now we can't change the title text size or use a custom font for the title.

Related

How can i set master/detail view side by side in portrait mode using uisplitviewcontroller

I am using the new UISplitViewController, coming with iOS 14 as follows:
let splitViewController = UISplitViewController(style: .doubleColumn)
splitViewController.preferredDisplayMode = .oneBesideSecondary
let primaryVC = PrimaryViewController()
splitViewController.setViewController(primaryVC, for: .primary)
let secondaryVC = SecondaryViewController()
splitViewController.setViewController(secondaryVC, for: .secondary)
It works as expected, but i wanted to get a similiar result like this:
Landscape
i want to only have a expand icon in the secondaryViewController to hide or show the sidebar as you maybe also know from the Apple Notes App for iPad. I want to hide/remove default Sidebar Icon.
Portrait
i want the primary and secondary view side-by-side. With the new UISplitViewController, the primary view always collapsed and you get a "Back" Button in the NavigationBar.
So is there a way to manipulate or customize the new UISplitViewController to get the result, as i described above?
What i tried
switch to the "classic" UISplitViewController like this:
let splitViewController = UISplitViewController(style: .unspecified)
but with the style unspecified i get the following runtime error:
API misuse. -initWithStyle: may not be used with UISplitViewControllerStyleUnspecified
I think that in your case the style should be doubleColumn, as it's what you want to achieve in both portrait and landscape mode.
Try to implement this method in the UISplitViewControllerDelegate:
optional func splitViewController(_ splitViewController: UISplitViewController,
collapseSecondary secondaryViewController: UIViewController,
onto primaryViewController: UIViewController) -> Bool
And if not already set, set your UISplitViewController's delegate. Return false if you don't want to collapse the split view controller (which means that if not collapsed, it will display two columns; Which is your case).

UIKit TabBar with SwiftUI View

I am updating my existing UIKit to use SwiftUI in some parts where I feel comfortable about being able to replace all of it with SwiftUI. It is a tab application, so there are 3 tabs and one of it are Settings, which I am replacing with SwiftUI.
My tab bar is configured to only show images and no titles (the issue I need help with would also occur with labels shown).
Now in UIKit I do this:
private let settingsViewController: UIViewController = UIHostingController<SettingsView>(SettingsView())
and later on before showing it:
settingsViewController.navigationItem.title = "Settings".
However from then on SwiftUI takes on with its view modifier: .navigationBarTitle("Text"), which I use for nested view controllers (pushed via NavigationLink), as UIKit cannot access those views to set a title.
The issue is however, that whenever .navigationBarTitle is used (same with setting the view's title property in UIKit, it sets the current tab bar items title. For UIKit there is always a way to set the navigationItem.title instead of title.
Is there any way to set the navigation bar title but not the tab bar title itself in SwiftUI?
Thanks
This is to be a bug in iOS. Please file a bug report to Apple.
I just discovered a workaround for this issue:
Create a custom subclass of UINavigationController and use it as the navigation controller containing your settingsViewController.
class WorkaroundUINavigationController: UINavigationController {
override var title: String? {
get { tabBarItem.title }
set { navigationItem.title = newValue }
}
}

StatusBar text color doesn't change to Light Content [duplicate]

Adding
application.statusBarStyle = .lightContent
to my AppDelegate's didFinishLaunchingWithOptions method nor adding
override var preferredStatusBarStyle: UIStatusBarStyle {
return UIStatusBarStyle.lightContent
}
to the VC no longer works on iOS12/Xcode10
Any ideas?
This has nothing to do with iOS 12. You just have the rules wrong.
In a navigation controller situation, the color of the status bar is not determined by the view controller’s preferredStatusBarStyle.
It is determined, amazingly, by the navigation bar’s barStyle. To get light status bar text, say (in your view controller):
self.navigationController?.navigationBar.barStyle = .black
Hard to believe, but true. I got this info directly from Apple, years ago.
You can also perform this setting in the storyboard.
Example! Navigation bar's bar style is .default:
Navigation bar's bar style is .black:
NOTE for iOS 13 This still works in iOS 13 as long as you don't use large titles or UIBarAppearance. But basically you are supposed to stop doing this and let the status bar color be automatic with respect to the user's choice of light or dark mode.
If you choose a same status bar color for each View Controller:
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Ad this to your Info.plist and set status bar color from Project -> Targets -> Status Bar Style by desired color.
On the other hand, in your case, you have a navigation controller which is embedded in a view controller. Therefore, you want to different status bar color for each page.
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
Ad this to your Info.plist. Then, create a custom class for your NavigationController. After that you can implement the method:
class LightContentNavigationController: UINavigationController {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
Thats it! Please, inform me whether this was useful!
If Matt's answer isn't working for you, try adding this line of code before you present your viewController.
viewController.modalPresentationCapturesStatusBarAppearance = true
I encountered a bug where setting modalPresentationStyle to overFullScreen does not give the status bar control to the presented view controller or navigation controller.
I was using navigation controller for each tab of UITabBarController. Subclassing UINavigationController and overriding childForStatusBarStyle fixed the issue for me.
class MyNavigationController: UINavigationController {
open override var childForStatusBarStyle: UIViewController? {
return topViewController?.childForStatusBarStyle ?? topViewController
}
}
If you have a modal UIViewController the situation becomes very tricky.
Short answer:
Present modal using UIModalPresentationStyle.fullScreen
override preferredStatusBarStyle (in your modal vc)
call setNeedsStatusBarAppearanceUpdate() in viewWillAppear (in your modal vc)
If you don't want to use UIModalPresentationStyle.fullScreen you have to set modalPresentationCapturesStatusBarAppearance
According to apple doc:
When you present a view controller by calling the
present(_:animated:completion:) method, status bar appearance
control is transferred from the presenting to the presented view
controller only if the presented controller's modalPresentationStyle
value is UIModalPresentationStyle.fullScreen. By setting this property
to true, you specify the presented view controller controls status bar
appearance, even though presented non-fullscreen.
The system ignores this property’s value for a view controller
presented fullscreen.
You can set
vc.modalPresentationCapturesStatusBarAppearance = true
to make the customization works.
Customizing UINavigationController can fix the issue
class ChangeableStatusBarNavigationController: UINavigationController {
override var preferredStatusBarStyle: UIStatusBarStyle {
return topViewController?.preferredStatusBarStyle ?? .default
}
}
Ref: https://serialcoder.dev/text-tutorials/ios-tutorials/change-status-bar-style-in-navigation-controller-based-apps/

Swift change tabBar title after touching a tabbar item

I have app with a tabBar and Navigation controller.
How can I change the tabBar title (visible in top application's window) when I touch it in tabbar?
For example i have these items in tabbar:
Pizza
Beer
Orange
Apple
After I click pizza I want to have pizza in the title app in the top menu.
How can I do this?
Depending on your implementation, one of the below methods should work for you.
self.navigationItem.title = "title"
or
self.navigationBar.topItem?.title = "title"
If you are using a custom tabbar made with UIButtons and container
view, then add this to the button action or if you are using a native
UITabBarController, then set it's delegate to self and call this on
the didSelectViewController delegate method of the UITabBarController.
.
EDIT
After seeing your code, you need to use this property :
self.tabBarController?.navigationItem.title = "Profile"
and call this in every view controller's viewWillAppear, example for ProfileViewController
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.tabBarController?.navigationItem.title = "Profile"
}
Also, make sure that in storyboard, you set the view controller's class to the respective code class like :
and remove the text from the custom navigation bar you used:

UITabBarController customisation page top bar colour swift

How do I change the colour of the top bar of the customisation page of the more view controller. Please see the linked image. Sorry I can't post image here because of my low reputation.
Screenshot Image
Edited with more info:
I have managed to change the background color using the following code. But cant change the color of the top bar.
func tabBarController(tabBarController: UITabBarController, willBeginCustomizingViewControllers viewControllers: [AnyObject]) {
var editView : UIView = tabBarController.view.subviews[1] as! UIView
editView.backgroundColor = UIColor.blackColor()
}
Basically 2 Ways you can achieve this if you are using Global Unique colour in the app for All navigation bar
Use this Solution on App Launch:
UINavigationBar.appearance().barTintColor = UIColor.redColor()
Or if you want to change the Color of More navigationcontroller only then
Use this Solution by getting the Tabbar Reference :
self.tabBarController?.moreNavigationController.navigationBar.barTintColor = UIColor.greenColor()
You can use second solution in the First viewcontroller of the Tab, because that contains your tabbar reference