Hide status bar only on iPhone 5, 5s, SE - iphone

Is it possible to hide status bar of my app only for iPhones with small screens? Thanks

iPhone 5, 5S and SE have a screen width of 320. In your AppDelegate you could do the following:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if UIScreen.main.bounds.width == 320 {
application.isStatusBarHidden = true
}
return true
}
And go to your info.plist and add a new value:
View controller-based status bar appearance set the value to NO. The status bar will now be hidden for iPhone 5, 5S and SE.

Related

Swift: Setting StatusBar color on IOS13+ (Using statusBarManager)

I want to define by code the color of my status bar, the way I found it was this one but it is deprecated. Does anyone know what the new way of doing this is? This warning is following me in all my codes
This code is working but with the warning
The code for whoever wants:
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
return true
}
By using UIStatusBarManager as mention in the warning, you can not also able to set style.
because statusBarManager is the get only property. Check Here
open var statusBarStyle: UIStatusBarStyle { get }
You have to override the preferredStatusBarStyle
Like this
class ViewController: UIViewController {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
If you want to change the status bar style to all of your view controllers, you can set it inside the Info.plist.
Step 1:
Add View controller-based status bar appearance key and set No value
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Step 2: Add Status bar style key and set style like Light Content
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
If you want a different style based on controller then,
Step 1:
Add View controller-based status bar appearance key and set Yes value
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
Step 2: override preferredStatusBarStyle within view controller.
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
Here is a good article about How to set status bar style.
You can simply add Appearance key with value Light in your Info.plist
Please check this image for reference

iOS 14 display status bar in landscape

Since iOS 8, status bar is hidden in landscape by default, I want to make it visible. I created a new empty project and tried several things from other topics but none of these work:
First solution I tried (I also added the UIViewControllerBasedStatusBarAppearance key to the Info.Plist and tested with it set either to true or false):
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
setNeedsStatusBarAppearanceUpdate()
}
override var prefersStatusBarHidden: Bool {
return false
}
}
Second solution I tried was to use the deprecated method setStatusBarHidden in the App Delegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
application.setStatusBarHidden(false, with: .none)
// Override point for customization after application launch.
return true
}
In both cases status bar does not appear in landscape. Is there any way to see it ?
Your code is correct (this is all you need in a new vanilla iOS app project):
override var prefersStatusBarHidden: Bool {
return false
}
The problem is that this works only up through iOS 12. In iOS 13 and later, the runtime stopped interpreting a value of false to allow you to override the hiding of the status bar in landscape on an iPhone. Similarly, calling application.setStatusBarHidden fails to show the status in landscape.
This is probably a side effect of the UIWindowScene architecture that was introduced in iOS 13. Or it might be intended to make all iPhone models behave the same way (with or without bezel).

Globally Change The Border Color Of UITextField?

I'm trying to globally change the UITextField color to white when my application loads.
I call my Theme manager like:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let theme = ThemeManager.currentTheme()
ThemeManager.applyTheme(theme: theme)
return true
}
Then in my theme manager, I set the border color like:
UITextField.appearance().layer.borderWidth = 5.0
UITextField.appearance().layer.borderColor = UIColor.white.cgColor
UITextField.appearance().textColor = UIColor.white
It seems like every other UI elment takes the changes fine, but this doesn't persist throughout the application. If I manually set the color on specific TextFields it works fine, but was trying to avoid that, am I doing something wrong?
Thanks.

Change colour of back bar button item only in swift

I am trying to change the colour of the back bar button item in swift navigation bar.
Ultimately I aim to make something line this for the navbar:
This is my current code which gives me three back arrows as the back button item but how do I change the colour so it is three different colours in one bit of text? (Green, Yellow, Red).
func setCustomBackImage() {
navigationItem.backBarButtonItem = UIBarButtonItem(title: "<<<", style: .plain, target: nil, action: nil)
}
There is a much more easier way, since you said " I'm still fairly new to swift ", here you go !
//add this in AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let backArrowImage = UIImage(named: "icon50")
let renderedImage = backArrowImage?.withRenderingMode(.alwaysOriginal)
UINavigationBar.appearance().backIndicatorImage = renderedImage
UINavigationBar.appearance().backIndicatorTransitionMaskImage = renderedImage
return true
// This will change all back-arrows to whatever image you want
}
Here "icon50" should that "<<<" image. Td:lr , use an image.
Hope it helps :)
This seems to be something like what you're describing:
Pretty simple if you use an image instead of a title for your bar button item.

swift - implement the func to change background color for the whole screen for multiple tabs

my app has 04 tabs, i want to write a func to change the background color for the whole screen: status bar, naviation bar, etc.
i want this because when i change color in the func then the whole app will change
below i just change to the top. but too complicated
what i have done is change the status bar text to white
//change text of status bar to white
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
go to the Storyboard, Select the View Controller and in the Editor menu Select Embed in Navigation Controller. Select the Navigation Bar and in the Attribute Inspector set the Bar Tint color to red.
in appDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UINavigationBar.appearance().barStyle = .blackOpaque
return true
}