how to set full Full Screen in SVProgressHUD in swift? - swift

i'm using The library SVProgressHUD for my project to show a spinning circle loader:
SVProgressHUD.setBackgroundColor(UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 0.3))
SVProgressHUD.setForegroundColor(UIColor.white)
SVProgressHUD.show()
my question is how do i make the background to full screen ?
and how do i block the presses in the background while it is displaying ?
the library:
https://github.com/SVProgressHUD/SVProgressHUD

You have to set background layer color to color you need. But don't forget, if you want to change background layer color, you also have to set default mask type as .custom
SVProgressHUD.setDefaultMaskType(.custom)
SVProgressHUD.setBackgroundLayerColor(.black) // your custom color
If you want to know how to customize other properties, have a look
here.

Related

trying to change the background color in a fading manner

I'm trying to change the background color from an image to white in a fading manner. Here's the current code I have:
UIView.animate(withDuration: 1, delay: 0, animations: { () -> Void in self.answer.alpha = 0})
UIView.animate(withDuration: 1, delay: 0, animations: { () -> Void in self.continueLabel.alpha = 0})
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [unowned self] in self.view.backgroundColor = UIColor(displayP3Red: 255/255, green: 255/255, blue: 255/255, alpha: 1)}
As you can see I'm also having two other items fade out, which are working fine. Right now though I just have the background change to white with a delay of 0.5 seconds, which doesn't look as smooth as I'd like. Ideally I'd like to have all three (the two labels and the background) fade together, with delay 0 and duration 1. I tried setting the background to white with alpha = 0, and then changing the alpha to 1 in a fading manner but that did not work either. If anybody could please provide some insight I'd greatly appreciate it. Thanks!
Also, below I've included how I called the image background, just in case it's helpful:
UIGraphicsBeginImageContext(self.view.frame.size)
UIImage(named: "nyc")?.draw(in: self.view.bounds)
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
self.view.backgroundColor = UIColor(patternImage: image)
Ideally I'd like to have all three (the two labels and the background) fade together, with delay 0 and duration 1
Then why didn't you do that? You animated the alphas; why didn't you animate the background color? I mean to say, it isn't going to animate unless you tell it to animate:
UIView.animate(withDuration: 1, delay: 0, animations: { self.view.backgroundColor = UIColor(displayP3Red: 255/255, green: 255/255, blue: 255/255, alpha: 1)})
By the way, did you know you're allowed to animate more than one view in one animations block? Plus you don't need an in line for a known function type. So the whole thing can be rewritten a lot more neatly.
UIView.animate(withDuration: 1, delay: 0, animations: {
self.answer.alpha = 0
self.continueLabel.alpha = 0
self.view.backgroundColor = // whatever
})
EDIT: I’m going to guess that the animation of the background color doesn't work for you because your background color is a pattern. In that case you will need to use trickery! You’ll need another view in front of the background that animates from clear color to white color. — On the other hand, maybe you should never have used a pattern image to start with. Personally I never use them. If I want a backdrop, I put an image view behind everything else. If you had done that, you could now fade the image view's alpha along with the others, revealing the empty white window and view behind everything.

iOS 13 system color for UIButton

Apple recommends using system colors to adapt apps to light and dark mode automatically, for example:
myLabel.textColor = UIColor.secondaryLabel
Here Apple lists various properties to be used, such as the one in the example above, and system colors for background, placeholder text, and more.
But it doesn't list a property for UIButton elements.
Which property or other method should we use to adapt UIButtons to theme changes?
As of now, I'm doing this:
myButton.tintColor = UIColor.link
which is supposedly for links but is the only "clickable" property I found.
I'm not looking to use something like UIColor.systemRed, rather something like UIColor.systemBackground, which adapts automatically to the current theme.
I hope you create colored Assets not one by one. You can use this function to tint images as a extension of UIImageView. I also use the same technique for buttons.
func setImageAndColor(image: UIImage, color: UIColor) {
let templateImage = image.withRenderingMode(.alwaysTemplate)
self.image = templateImage
self.tintColor = color
}
In case you want to define all you own colors, I suggest to create a singleton class named Colors:
import UIKit
class Colors {
static let shared = Colors()
var statusBarStyle: UIStatusBarStyle = .lightContent
private init(){}
func setLightColors() {
statusBarStyle = .darkContent
yourColor = UIColor( // choose your favorite color
styleColor = UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 1)//white
labelColor = UIColor(red: 15/255, green: 15/255, blue: 15/255, alpha: 1)
subLabelColor = UIColor(red: 25/255, green: 25/255, blue: 25/255, alpha: 1)
............ set values for all colors from here.
}
func setDarkColors() {
statusBarStyle = .lightContent
yourColor = // choose your favorite color
............
}
// set initial colors
var yourColor: UIColor =
}
If somebody is interested in the whole Colors class, text me or comment below.
I access the colors singleton by:
Colors.shared.yourColor
Also for first configuration I set in the very first VC the darkmode number (0-Auto; 1-On; 2-Off):
if darkmodeNumber == 0 {
if traitCollection.userInterfaceStyle == .light {
print("Light mode")
Colors.shared.setLightColors()
} else {
print("Dark mode")
Colors.shared.setDarkColors()
}
} else if darkmodeNumber == 1 {
Colors.shared.setDarkColors()
} else if modeNumber == 2 {
Colors.shared.setLightColors()
}
}
The statusbar should then change also the right way.
Use any system colors you like. They are all adaptive. I applied the system gray color to a button's text:
The color changes when we switch between light and dark mode.

SceneKit : how to change the color of an object

I read the docs from Apple and they say that the solution is inside UIKit; unfortunately, I'm not writing code for IOs but MacOS so no UIKit.
What is the correct object which allows me to change the color?
sphereGeometry.firstMaterial?.diffuse.contents = ??
I found the solution:
sphereGeometry.firstMaterial?.diffuse.contents = NSColor(calibratedRed: 0.3, green: 0.5, blue: 0.4, alpha: 1 )
NSColor is the object to use to get the job done.

Changing Tab Bar Color (Swift)

I am trying to change the tab bar color in a view controller in XCode using swift. I have a hex that I matched up to an RGB value and I am trying to set that in this code. (Which does not work)
let color = UIColor(red: 41, green: 40, blue: 39, alpha: 1.0)
UITabBar.appearance().barTintColor = color
However this code does:
UITabBar.appearance().barTintColor = UIColor.whiteColor()
Can anyone explain why this doesn't work, and what I can do to fix it?
To use RGB values, just divide them by 255.0. This will produce a float value between 0 and 1.
let color = UIColor(red: 41.0/255.0, green: 40.0/255.0, blue: 39.0/255.0, alpha: 1.0)
It doesn't work because all of your RGB components are greater than 1, which is the maximum available value per-channel. You're probably thinking of the color channels as bytes, but that wouldn't scale to varying color bit depths. (For example, it was common to render to RGB565, not RGBA8888 in early versions of iOS. And you can probably expect Apple to make screens with 16-bit accuracy the norm, in the near future.) Floats from 0 to 1 are employed, to divorce the bit depth from the color representation.
https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UIColor_Class/index.html#//apple_ref/occ/instm/UIColor/initWithRed:green:blue:alpha:
iOS 10 Swift 3.0
If you don't mind to use swift frameworks then us UINeraida to change Tabbar background as UIColor or HexColor or UIImage and change complete forground color.
For UITabBar
neraida.tabbar.background.color.uiColor(UIColor.orange, isTranslucent: false, viewController: self)
//change tab bar tint color //(select,unselect)
neraida.tabbar.foreground.color.uiColor((UIColor.white,UIColor.green), viewController: self)
//set Background Image for tab bar
neraida.tabbar.background.image("background", isTranslucent: false, viewController: self)
This way worked for me:
tabBarController?.tabBar.backgroundColor = .red

Serious SpriteKit UIColor bug on iPhone 5S

I've found a serious swift-bug in SpriteKit while working with SKSpriteNodes and their colors.
This code works fine on all iPhones beside the iPhone 5S:
var color1 = UIColor(red: 123/255, green: 123/255, blue: 123/255, alpha: 1)
var color2 = UIColor(red: 123/255, green: 123/255, blue: 123/255, alpha: 1)
var sprite = SKSpriteNode(color: color1, size: CGSizeMake(100, 100))
if(sprite.color == color2){
println("Same color")
}
As you see, the two colors are the absolut same. But on the iPhone 5S simulator, the if isn't called.
Has somebody else the same problem and can provide a solution?
According to the documentation here:
Sprite Kit works only with solid colors. For best results, use the
preset colors provided by the platform class or a custom color defined
in the RGBA device color space.
As a result somehow the SKSpriteNode has made some changes to the color parameter in the init function. You can see it if you call encode:
sprite.color.encode() // 140,646,370,382,768
color1.encode() // 140,646,367,110,928
If you use predefined color values, then your problem goes away:
var color3 = UIColor.blueColor()
var sprite3 = SKSpriteNode(color: color3, size: CGSizeMake(100, 100))
sprite3.color == color3 // true
You are comparing pointer values, not the actual color. Seeing that these are UIColor instances, you have to compare them using isEqual (showing ObjC code as I don't know what it looks like in Swift - or perhaps Swift is in fact using isEqual behind the scenes):
if ([sprite.color isEqual:color2])
If implemented correctly by UIColor this will compare the actual color values rather than the pointers.