This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
subscript (i: Int) -> Character { | |
get { | |
assert(i < self.characters.count && i >= 0, "Index out of range.") | |
return self[self.index(self.startIndex, offsetBy: String.IndexDistance(i))] | |
} | |
set { | |
assert(i < self.characters.count && i >= 0, "Index out of range.") | |
let index = self.index(self.startIndex, offsetBy: String.IndexDistance(i)) | |
let endIndex = self.index(self.startIndex, offsetBy: String.IndexDistance(i+1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getRandomColor(minVal: Int = 0, maxVal: Int = 255) -> UIColor { | |
// get random values between the min value (0) and max value (255): | |
let randomRed: Int = Int(arc4random_uniform(UInt32(maxVal-minVal+1)))+minVal | |
let randomGreen: Int = Int(arc4random_uniform(UInt32(maxVal-minVal+1)))+minVal | |
let randomBlue: Int = Int(arc4random_uniform(UInt32(maxVal-minVal+1)))+minVal | |
return UIColor(red: CGFloat(Float(randomRed) / Float(255)), green: CGFloat(Float(randomGreen) / Float(255)), blue: CGFloat(Float(randomBlue) / Float(255)), alpha: 1.0) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get a complementary color to this color: | |
func getComplementaryForColor(color: UIColor) -> UIColor { | |
let ciColor = CIColor(color: color) | |
// get the current values and make the difference from white: | |
let compRed: CGFloat = 1.0 - ciColor.red | |
let compGreen: CGFloat = 1.0 - ciColor.green | |
let compBlue: CGFloat = 1.0 - ciColor.blue | |
NewerOlder