Using Hex Color Codes! (Swift 4 in Xcode)

preview_player
Показать описание
Today we dive into using hex color codes. Something that is very useful for products to get the perfect color you're looking for & cross managing that with your website and what not. Enjoy!

Music by Andrew ApplePie

~Social Stuff~
Twitter/Instagram - @archetapp
Рекомендации по теме
Комментарии
Автор

Today we dive into using hex color codes. Something that is very useful for products to get the perfect color you're looking for & cross managing that with your website and what not. Enjoy! :D

Archetapp
Автор

4:27 ^^ Gem bit shifting. Filtering out what is not red & xff0000, then shifting this 2 bytes to the right( or left depending on endianness ) to make them available in the uint8 space.

gjermundification
Автор

Thanks, Jared. 👍🏼 I always wondered why support for hex colors isn't just built in. They seem way easier to work with.

bigmtnstudio
Автор

8:48 the window no longer looks like that, there are actually NO options to get another looking ui for the colour pallet. can you help? followed your steps by step.

dasautohunter
Автор

Hey Jared, this is awesome!
Thanks for all of your tutorials, they are by far the best on youtube!!Is there any way that you could make a new tutorial for your Maze Game but in Swift 4, please?

jaychesson
Автор

is there a more recent video i can watch? thanks ahead

dasautohunter
Автор

Amazing videos! I just subscribed to your channel and have been watching your videos to try and learn coding with Xcode. I had a question. How do you get or make images for creating an app? Let’s say for example, I want to create my first game app but I need background images and other game images. How can I create them?

JEii
Автор

sir I have two hex value and I have to use one form left and second from right and end them in the middle so how can I use this in your code

rahulmishra
Автор

Thanks for the video.

PS: You can always delete 'import Foundation' when you are importing UIKit. UIKit already has Foundation classes. 😉
Not a major thing but just I like to use minimum imports.😬😬😬

jai
Автор

Very helpful Jared! Thank you for sharing

raulgutierrez
Автор

Why didn't you create an init instead of a func? Is using a func better or something? I find more logical to directly initialize a UIColor from a hex code. Just asking, I'm kinda a noob xD

erickpadilla
Автор

How to prefer a row of the table so that it is at the top help

abololaw
Автор

Hey Jared, may i ask what you do for a living? :)

m_
Автор

Why do you call the init method explicitly?  These are the same?
            let color1 = UIColor(red: 0.1, green: 0.1, blue: 0.1, alpha: 1)
            let color1 = UIColor.init(red: 0.1, green: 0.1, blue: 0.1, alpha: 1)

michaelmellinger
Автор

Interesting tutorial with good example of Scanner and scanHexInt32 but given that this is supposed to be using Hex codes for colors in your code, I am not sure this is the right approach.
Your function should be static, so you don't have to instantiate UIColor. Using Swift 4 naming conventions, it should be something like:

static func color ( fromHex: String) -> UIColor { ... }

A simple function would be 

static func color(from: UInt32) -> UIColor {
     return UIColor(red: CGFloat( (from & 0xFF0000) >> 16 ) / 255, green: CGFloat((from & 0x00FF00) >> 8) / 255, blue: CGFloat(from & 0x0000FF) / 255, alpha: 1)
}

so you can call it as color = UIColor.color(0x880000) and allow the compiler to parse your hex rather than the runtime (and is substantially faster). But a better function would use generics:

    static func color<T>( from: T ) -> UIColor where T: BinaryInteger {
        let rgb: UInt32 = UInt32(from)
        return UIColor(red: CGFloat( (rgb & 0xFF0000) >> 16 ) / 255, green: CGFloat((rgb & 0x00FF00) >> 8) / 255, blue: CGFloat(rgb & 0x0000FF) / 255, alpha: 1)
    }

Using T rather than UInt32 allows you to use code like:

  let myInt = 0x880000
  let color = UIColor.color(myInt)

And if you want to get really clever, add this:

   assert( from.bitWidth >= 24, "Insufficient bitwidth (\(from.bitWidth) to fully represent a color" )

as the first line to ensure all is well with the particular numeric being supplied to represent the color. The great thing about this assert is that in is only evaluated during debug.

Mythlandia
Автор

thanks for sharing (from Argentina)!!!

valeria-
Автор

Couldnt you instead make a convenience init that accept a hex string? Then you could just do: UIColor(hex:

ctkrocks
Автор

How to integrate PayPal in iOS using swift

shaileshprabhudesai
Автор

great vid! would have been better as a class function rather than an instance function.

puhgeh
Автор

Why in a modern language would this not be a feature of the language? Why wouldn’t hex be allowed input automatically?

Sure you can just shift out the colours, but doing this millions of times in swift might be pretty slow, and I don’t get, considering under the hood they use hex, why we can’t just input hex??? It’s mind boggling oh stupid. Apple needs to fix this. This is just bloody stupid.

anthonypace
welcome to shbcf.ru