Issue With ViewController I am using PageMenu Third party library - uiview

When Controller present it shows white space. When I am clicking another tab and comeback to the same tab. which shown white space. Then working fine . let me know how can I remove white space in it.(White space is showing above of Buy MB for BTC)
Screenshot :
override func viewDidAppear(_ animated: Bool) {
pager()
}
func pager()
{
let buy = storyboard?.instantiateViewController(withIdentifier: "BuyMBVCSID") as! BuyMBVC
buy.parentNavigationController = navigationController!
buy.title = "Buy MB"
controllerArray.append(buy)
let sell = storyboard?.instantiateViewController(withIdentifier: "SellMBVCSID") as! SellMBVC
sell.parentNavigationController = navigationController!
sell.title = "Sell MB"
controllerArray.append(sell)
// Customize menu (Optional)
let parameters: [CAPSPageMenuOption] = [
.scrollMenuBackgroundColor(UIColor(red: 72/255.0, green: 175/255.0, blue: 230/255.0, alpha: 1.0)),
.viewBackgroundColor(UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)),
.selectionIndicatorColor(UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 1.0)),
.addBottomMenuHairline(false),
.menuItemFont(UIFont(name: "Times New Roman", size: 16)!),
.menuItemWidth((self.pagerView.frame.width-30)/3),
.menuHeight(50.0),
.enableHorizontalBounce(true),
.menuItemWidthBasedOnTitleTextWidth(false),
.selectedMenuItemLabelColor(UIColor.white),
.unselectedMenuItemLabelColor(UIColor.white),
.menuItemSeparatorWidth(4.5),
.useMenuLikeSegmentedControl(false),
.menuItemSeparatorRoundEdges(true),
.selectionIndicatorHeight(2.0),
.menuItemSeparatorPercentageHeight(0.0),
]
// Initialize scroll menu
pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRect(x: 0.0, y: 0.0, width: self.pagerView.frame.width, height: self.pagerView.frame.height), pageMenuOptions: parameters)
self.pagerView.addSubview(pageMenu!.view)
// End Pagemenu
}

Change
.selectionIndicatorColor(UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 1.0))
to
.selectionIndidcatorColor(UIColor.clear)
that should do the trick

Related

How can I make a collectionViewCell like the one on Apple's app Shortcuts?

I want to make a collectionViewCell like the one on Apple's app Shortcuts, especially with the random background colors.
Shortcuts app UI:
First of all I'm sorry if my question wasn't clear, however I think solved my problem. I wanted to create a similar collectionViewCell to the one on the Shortcuts app and I think I did pretty well, here's what I've done...
Final result
I put the colors I wanted into a Hash Table and then generated a random key to get the pictures array and then created an extension to the UIView class to make the gradient and passed the index of the colors array to the gradient function from my cellRandomBackgroundColors(), here's my collectionViewCell class and the extension if anyone want it.
import UIKit
class MainCollectionViewCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
setupCell()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
//MARK:- UI
let iconImageView: UIImageView = {
let imageView = UIImageView()
imageView.image = UIImage(named: "Folder")
imageView.contentMode = .scaleAspectFit
return imageView
}()
let checklistNameLabel: UILabel = {
let label = UILabel()
label.text = "List"
label.textColor = UIColor.white
label.font = UIFont.boldSystemFont(ofSize: 19)
label.textAlignment = .left
return label
}()
let remainingsLabel: UILabel = {
let label = UILabel()
label.text = "2 Remaining"
label.textColor = UIColor.white
label.font = UIFont.systemFont(ofSize: 13)
label.textAlignment = .left
return label
}()
let editButton: UIButton = {
let button = UIButton(type: UIButton.ButtonType.custom) as UIButton
button.setImage(UIImage(named: "More"), for: UIControl.State.normal)
return button
}()
//MARK:- Setup Cell
func setupCell() {
roundCorner()
gradientBackgroundColor()
setCellShadow()
self.addSubview(iconImageView)
self.addSubview(checklistNameLabel)
self.addSubview(remainingsLabel)
self.addSubview(editButton)
iconImageView.anchor(top: safeTopAnchor, left: safeLeftAnchor, bottom: nil, right: nil, paddingTop: 8, paddingLeft: 8, paddingBottom: 0, paddingRight: 0, width: 36, height: 36)
checklistNameLabel.anchor(top: iconImageView.bottomAnchor, left: safeLeftAnchor, bottom: nil, right: nil, paddingTop: 18, paddingLeft: 8, paddingBottom: 0, paddingRight: 0)
remainingsLabel.anchor(top: checklistNameLabel.bottomAnchor, left: safeLeftAnchor, bottom: nil, right: nil, paddingTop: 4, paddingLeft: 8, paddingBottom: 0, paddingRight: 0)
editButton.anchor(top: safeTopAnchor, left: nil, bottom: nil, right: safeRightAnchor, paddingTop: 8, paddingLeft: 0, paddingBottom: 0, paddingRight: 8, width: 36, height: 36)
}
//MARK:- Methods
func cellRandomBackgroundColors() -> [UIColor] {
//Colors
let red = [#colorLiteral(red: 0.9654200673, green: 0.1590853035, blue: 0.2688751221, alpha: 1),#colorLiteral(red: 0.7559037805, green: 0.1139892414, blue: 0.1577021778, alpha: 1)]
let orangeRed = [#colorLiteral(red: 0.9338900447, green: 0.4315618277, blue: 0.2564975619, alpha: 1),#colorLiteral(red: 0.8518816233, green: 0.1738803983, blue: 0.01849062555, alpha: 1)]
let orange = [#colorLiteral(red: 0.9953531623, green: 0.54947716, blue: 0.1281470656, alpha: 1),#colorLiteral(red: 0.9409626126, green: 0.7209432721, blue: 0.1315650344, alpha: 1)]
let yellow = [#colorLiteral(red: 0.9409626126, green: 0.7209432721, blue: 0.1315650344, alpha: 1),#colorLiteral(red: 0.8931249976, green: 0.5340107679, blue: 0.08877573162, alpha: 1)]
let green = [#colorLiteral(red: 0.3796315193, green: 0.7958304286, blue: 0.2592983842, alpha: 1),#colorLiteral(red: 0.2060100436, green: 0.6006633639, blue: 0.09944178909, alpha: 1)]
let greenBlue = [#colorLiteral(red: 0.2761503458, green: 0.824685812, blue: 0.7065336704, alpha: 1),#colorLiteral(red: 0, green: 0.6422213912, blue: 0.568986237, alpha: 1)]
let kindaBlue = [#colorLiteral(red: 0.2494148612, green: 0.8105323911, blue: 0.8425348401, alpha: 1),#colorLiteral(red: 0, green: 0.6073564887, blue: 0.7661359906, alpha: 1)]
let skyBlue = [#colorLiteral(red: 0.3045541644, green: 0.6749247313, blue: 0.9517192245, alpha: 1),#colorLiteral(red: 0.008423916064, green: 0.4699558616, blue: 0.882807076, alpha: 1)]
let blue = [#colorLiteral(red: 0.1774400771, green: 0.466574192, blue: 0.8732826114, alpha: 1),#colorLiteral(red: 0.00491155684, green: 0.287129879, blue: 0.7411141396, alpha: 1)]
let bluePurple = [#colorLiteral(red: 0.4613699913, green: 0.3118675947, blue: 0.8906354308, alpha: 1),#colorLiteral(red: 0.3018293083, green: 0.1458326578, blue: 0.7334778905, alpha: 1)]
let purple = [#colorLiteral(red: 0.7080290914, green: 0.3073516488, blue: 0.8653779626, alpha: 1),#colorLiteral(red: 0.5031493902, green: 0.1100070402, blue: 0.6790940762, alpha: 1)]
let pink = [#colorLiteral(red: 0.9495453238, green: 0.4185881019, blue: 0.6859942079, alpha: 1),#colorLiteral(red: 0.8123683333, green: 0.1657164991, blue: 0.5003474355, alpha: 1)]
let colorsTable: [Int: [UIColor]] = [0: red, 1: orangeRed, 2: orange, 3: yellow, 4: green, 5: greenBlue, 6: kindaBlue, 7: skyBlue, 8: blue, 9: bluePurple, 10: bluePurple, 11: purple, 12: pink]
let randomColors = colorsTable.values.randomElement()
return randomColors!
}
func gradientBackgroundColor() {
let colors = cellRandomBackgroundColors()
self.contentView.setGradientBackgroundColor(colorOne: colors[0], colorTow: colors[1])
}
func roundCorner() {
self.contentView.layer.cornerRadius = 12.0
self.contentView.layer.masksToBounds = true
self.contentView.layer.borderWidth = 1.0
self.contentView.layer.borderColor = UIColor.clear.cgColor
}
}
The extension to create the gradients.
import UIKit
extension UIView {
func setGradientBackgroundColor(colorOne: UIColor, colorTow: UIColor) {
let gradientLayer = CAGradientLayer()
gradientLayer.frame = bounds
gradientLayer.colors = [colorOne.cgColor, colorTow.cgColor]
gradientLayer.locations = [0.0, 1.0]
gradientLayer.endPoint = CGPoint(x: 1.0, y: 1.0)
gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.0)
layer.insertSublayer(gradientLayer, at: 0)
}
}

Gradient color as a Background color of UIButton in Swift4

I have a button and i'm trying to set its background color gradient.I have three hex values which i converted to RGB and written three values in my code and pass all the three values to the button frame. But when i run the app button background not changes according to the color i have set in the code. My code to get three color codes is this,
let gradientColor = CAGradientLayer()
gradientColor.frame = loginButton.frame
let color1 = UIColor(red: 183, green: 46, blue: 79, alpha: 1)
let color2 = UIColor(red: 232, green: 79, blue: 80, alpha: 1)
let color3 = UIColor(red: 145, green: 21, blue: 79, alpha: 1)
gradientColor.colors = [color1,color2,color3]
self.loginButton.layer.addSublayer(gradientColor)
Try this and see:
#IBOutlet weak var loginButton: UIButton!
func testGradientButton() -> Void {
let gradientColor = CAGradientLayer()
gradientColor.frame = loginButton.frame
gradientColor.colors = [UIColor.blue.cgColor,UIColor.red.withAlphaComponent(1).cgColor]
self.loginButton.layer.insertSublayer(gradientColor, at: 0)
}
Here is result:
Also note: Values for RGB colors in your code, are much higher than its normal value. See your console log, it might printed following error:
[Graphics] UIColor created with component values far outside the expected range. Set a breakpoint on UIColorBreakForOutOfRangeColorComponents to debug. This message will only be logged once.
Divide all values with 255.0 and use insertSubLayer function.
let color1 = UIColor(red: 183.0/255.0, green: 46.0/255.0, blue: 79.0/255.0, alpha: 1)
let color2 = UIColor(red: 232.0/255.0, green: 79.0/255.0, blue: 80.0/255.0, alpha: 1)
let color3 = UIColor(red: 145.0/255.0, green: 21.0/255.0, blue: 79.0/255.0, alpha: 1)
Here is result with your color code values:
func testGradientButton() -> Void {
let gradientColor = CAGradientLayer()
gradientColor.frame = loginButton.frame
let color1 = UIColor(red: 183.0/255.0, green: 46.0/255.0, blue: 79.0/255.0, alpha: 1)
let color2 = UIColor(red: 232.0/255.0, green: 79.0/255.0, blue: 80.0/255.0, alpha: 1)
let color3 = UIColor(red: 145.0/255.0, green: 21.0/255.0, blue: 79.0/255.0, alpha: 1)
gradientColor.colors = [color1.cgColor,color2.cgColor,color3.cgColor]
self.loginButton.layer.insertSublayer(gradientColor, at: 0)
}

Press down on button to change the color of CGRect using a value in an array. How can this be accomplished?

Hello Stack Overflow community,
I am working on a project in Xcode 8.0 using Swift 3.0. The application I am trying to develop is a life counter for Magic the Gathering for my class' final project. The first image is what appears on screen when the user navigates from the home screen of the app to the life counter screen.
Here's a link to an image that shows what the user sees when they navigate from the application's home screen to this view.
You will see in the photo that there is the view controller, named lifeCounterViewController, and inside of that view controller are two other views. These views are named player1View and player2View respectively.
Inside each of those views a rectangle is being drawn. It is a member of the CGRect class. The following code is from a cocoa touch swift file. It contains the code that has my override of the draw function.
//
// player1LifeCounterDrawing.swift
import UIKit
class player1LifeCounterDrawing: UIView {
let MagicRed = UIColor.init(red: 247.0/255.0, green: 170.0/255.0, blue: 146.0/255.0, alpha: 1.0)
let Purple = UIColor.init(red: 102.0/255.0, green: 0.0/255.0, blue: 204.0/255.0, alpha: 1.0)
let Magenta = UIColor.init(red: 102.0/255.0, green: 0.0/255.0, blue: 51.0/255.0, alpha: 1.0)
let Orange = UIColor.init(red: 255.0/255.0, green: 166.0/255.0, blue: 0.0/255.0, alpha: 1.0)
let Plum = UIColor.init(red: 179.0/255.0, green: 0.0/255.0, blue: 89.0/255.0, alpha: 1.0)
let Emerald = UIColor.init(red: 0.0/255.0, green: 204.0/255.0, blue: 102.0/255.0, alpha: 1.0)
let Teal = UIColor.init(red: 0.0/255.0, green: 153.0/255.0, blue: 153.0/255.0, alpha: 1.0)
let SlateBlue = UIColor.init(red: 0.0/255.0, green: 153.0/255.0, blue: 255.0/255.0, alpha: 1.0)
let Forest = UIColor.init(red: 51.0/255.0, green: 153.0/255.0, blue: 51.0/255.0, alpha: 1.0)
let NavyBlue = UIColor.init(red: 51.0/255.0, green: 102.0/255.0, blue: 153.0/255.0, alpha: 1.0)
let MagicBlue = UIColor.init(red: 157.0/255.0, green: 216.0/255.0, blue: 255.0/255.0, alpha: 1.0)
let MagicBlack = UIColor.init(red: 194.0/255.0, green: 179.0/255.0, blue: 180.0/255.0, alpha: 1.0)
let MagicGreen = UIColor.init(red: 141.0/255.0, green: 203.0/255.0, blue: 158.0/255.0, alpha: 1.0)
var colorLibrary = [UIColor]()
var index = 0
func fillLibrary(library: [UIColor]) -> [UIColor]{
let capture = [UIColor](arrayLiteral: MagicRed, MagicBlue, MagicGreen, MagicBlack, Purple, Magenta, Orange, Plum, Emerald, Teal, SlateBlue, Forest, NavyBlue )
return capture
}
func calling(){
colorLibrary = fillLibrary(library: colorLibrary)
}
override func draw(_ rect: CGRect){
calling()
let lineWidth = CGFloat(3.0)
let rectangle = CGRect(
origin: CGPoint(x: 0, y: 0),
size: CGSize(width: bounds.maxX, height: bounds.maxY)
)
let rectPath = UIBezierPath(
roundedRect: rectangle,
byRoundingCorners: UIRectCorner(rawValue: 0),
cornerRadii: CGSize(width: 0, height: 0)
)
rectPath.lineWidth = lineWidth
rectPath.lineCapStyle = CGLineCap.square
if index >= colorLibrary.count{
index = 0
}
colorLibrary[index].setFill()
colorLibrary[index].setStroke()
index += 1
rectPath.stroke()
rectPath.fill()
}
}
Now this solution works, but it is ugly. As you can see whenever the draw function is called the array named, colorLibrary, is being reinitialized.
I fear that this is a large waste of memory and I need help finding a solution so that whenever the user presses down on a button a call to setNeedsDisplay() is made and the setStroke() and setFill() methods color is changed to reflect the color represented in the colorLibrary at [index].
How can this be accomplished?
Also keep in mind that the proposed solution needs to work for both player1View and player2View. I have only shown the code in player1View, but it is the same in player2View only the number identifying which view is which has changed.
Again, in my mind this is a large waste of memory, and I would like to have this fixed before Tuesday since that is when I need to present my application to my class. If I can't get a working solution by then I'll just go with this current one.
Swift supports lazy initialisation to, among other things, avoid the duplication you are concerned about. You can replace your colorLibrary with:
lazy var colorLibrary: [UIColor] = [self.MagicRed, self.MagicBlue, self.MagicGreen,
self.MagicBlack, self.Purple, self.Magenta,
self.Orange, self.Plum, self.Emerald, self.Teal,
self.SlateBlue, self.Forest, self.NavyBlue]
Note this uses an array literal ([ ... ]).
Now the variable colorLibrary will be initialised on first use and its value retained.
(To be accurate the variable may be initialised more than once, in particular in multi-threaded scenarios, but this need not concern you.)
On another note you manage your index with code like:
if index >= colorLibrary.count{
index = 0
}
// use index...
index += 1
The common way to manage an index like this is to use modular arithmetic; that is arithmetic which wraps around, adding one to the maximum value results in the minimum value. (For a real world example consider an odometer or the counter on an electric meter, after reaching all 9's these cycle around to all 0's.)
Modular arithmetic can be perform using the mod operator %, which for this purpose you can think of as returning the remainder of a division. The above code outline becomes:
// use index...
index = (index + 1) % colorLibrary.count
and the if is avoided.
HTH
You already have everything set up, an instance variable for the array of colours etc, but you're recreating this array with every draw cycle when every time except the first you probably needn't be.
Consider changing the call to calling() function at the start of draw(_:) so that you can reuse the previous array of colours. This won't save any memory, but it will reduce the number of unnecessary and repeated allocations, significantly improving efficiency. best
if colorLibrary.count == 0 {
calling()
}
Changing the index inside of your draw code will result in increasing at every single draw (device rotation -> redraw, go to background and open again -> redraw, ...). But you only want to do it when pressing a button.
My suggestion is to extract the color and index functionality into a specialized class (because it is logic independent of ui, the view should only draw something not more). You can also use lazy loading to avoid to much object creations.
e.g.:
final class ColorLibrary {
// increase index logic (including overflow handling)
private var currentIndex: Int = 0
func increaseIndex() {
if currentIndex == colors.count - 1 {
currentIndex = 0
} else {
currentIndex += 1
}
}
// lazy loading: color array will be created only once and only if needed
private var _colors: [UIColor]?
private var colors: [UIColor] {
if _colors == nil {
_colors = [
UIColor.init(red: 247.0/255.0, green: 170.0/255.0, blue: 146.0/255.0, alpha: 1.0),
UIColor.init(red: 102.0/255.0, green: 0.0/255.0, blue: 204.0/255.0, alpha: 1.0),
UIColor.init(red: 102.0/255.0, green: 0.0/255.0, blue: 51.0/255.0, alpha: 1.0),
UIColor.init(red: 255.0/255.0, green: 166.0/255.0, blue: 0.0/255.0, alpha: 1.0),
UIColor.init(red: 179.0/255.0, green: 0.0/255.0, blue: 89.0/255.0, alpha: 1.0),
UIColor.init(red: 0.0/255.0, green: 204.0/255.0, blue: 102.0/255.0, alpha: 1.0),
UIColor.init(red: 0.0/255.0, green: 153.0/255.0, blue: 153.0/255.0, alpha: 1.0),
UIColor.init(red: 0.0/255.0, green: 153.0/255.0, blue: 255.0/255.0, alpha: 1.0),
UIColor.init(red: 51.0/255.0, green: 153.0/255.0, blue: 51.0/255.0, alpha: 1.0),
UIColor.init(red: 51.0/255.0, green: 102.0/255.0, blue: 153.0/255.0, alpha: 1.0),
UIColor.init(red: 157.0/255.0, green: 216.0/255.0, blue: 255.0/255.0, alpha: 1.0),
UIColor.init(red: 194.0/255.0, green: 179.0/255.0, blue: 180.0/255.0, alpha: 1.0),
UIColor.init(red: 141.0/255.0, green: 203.0/255.0, blue: 158.0/255.0, alpha: 1.0)
]
}
return _colors!
}
var currentColor: UIColor {
get { return colors[currentIndex] }
}
}
You can construct the object inside of your view now by:
private(set) var colorLibrary: ColorLibrary = ColorLibrary()
Accessing the color inside of your draw:
colorLibrary.currentColor.setFill()
At button press you may call now:
cardView.colorLibrary.increaseIndex()
cardView.setNeedsLayout()

My label do not show after the layer added in the self.view but View Hierarchy show

I drag my labels to my self.view in storyboard, you can see the white labels, in the gray vc, I am sorry for the tiny distinction to found :
Then I add a gradual layer use code :
let fromColor = UIColor.init(red: 243/255.0, green: 143/255.0, blue: 30/255.0, alpha: 1).cgColor
let centerColor = UIColor.init(red: 237/255.0, green: 90/255.0, blue: 36/255.0, alpha: 1).cgColor
let toColor = UIColor.init(red: 233/255.0, green: 28.0/255.0, blue: 36/255.0, alpha: 1).cgColor
gradul_layer = CAGradientLayer.init()
gradul_layer?.frame = CGRect.init(x: 0, y: 64, width: initFrame.width, height: initFrame.height)
gradul_layer?.colors = [
fromColor,
centerColor,
toColor
]
gradul_layer?.startPoint = CGPoint.init(x: 0.5, y: 0.3)
gradul_layer?.endPoint = CGPoint.init(x: 0.5, y: 0.7)
self.view.layer.addSublayer(gradul_layer!)
And then when I run my app in simulator (or device) can not show the label, but I can capture the View Hierarchy in Xcode, and I can see the label.
You see the picture, left is simulator(the labels did not show), right is the capture View Hierarchy(the labels shows up).
Update
My question is not how to let the label show in my screen, my doubt is why View Hierarchy show, my device or simulator will not.

Randomize color in XCode

I'm trying to randomize the text color of a label in XCode with some colors I already created, I've tried different ways and this is the closest I got.
override func viewDidLoad() {
super.viewDidLoad()
let color1 = UIColor(red: 1, green: 165/255, blue: 0, alpha: 1)
let color2 = UIColor(red: 80/255, green: 1, blue: 200/255, alpha: 1)
let color3 = UIColor(red: 150/255, green: 80/255, blue: 1, alpha: 1)
let color4 = UIColor(red: 1, green: 80/255, blue: 80/255, alpha: 1)
let color5 = UIColor(red: 80/255, green: 1, blue: 80/255, alpha: 1)
var randomEight = arc4random_uniform(5)+1
var randomColor:String = String(format:"color%i", randomEight)
randomLabel.textColor = randomColor
}
However, the randomColor variable is a String and I can't transform it to a UIColor.
Put all of the colors in an array, then use randomEight as the index in the array to get the right color. Also, you may want to check the integer division to make sure you get the right colors.
let color1 = UIColor(red: 1, green: 165/255, blue: 0, alpha: 1)
let color2 = UIColor(red: 80/255, green: 1, blue: 200/255, alpha: 1)
let color3 = UIColor(red: 150/255, green: 80/255, blue: 1, alpha: 1)
let color4 = UIColor(red: 1, green: 80/255, blue: 80/255, alpha: 1)
let color5 = UIColor(red: 80/255, green: 1, blue: 80/255, alpha: 1)
let colors = [color1, color2, color3, color4, color5]
let randomEight = Int(arc4random_uniform(UInt32(colors.count)))
randomLabel.textColor = colors[randomEight]
Put the colours in an array, then select a random index, e.g.:
let colors: [UIColor] = [ UIColor.redColor(),
UIColor.blueColor(),
UIColor.greenColor()
] // ^- replace with your own colors
let randomColor = colors[Int(arc4random_uniform(UInt32(colors.count)))]
Note the necessary casts to work with arc4random_uniform. Also note that the indices start at 0, so do not add 1 to the random number.
There is no need for the randomEight (why is it “eight” anyhow?), and if the single text colour is the only place you use the colour, you can even leave out the randomColor and assign directly to randomLabel.textColor.
let randomEight = arc4random_uniform(5)+1
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
if randomEight == 1 {
randomLabel.textColor = UIColor.cyanColor()
}
else if randomEight == 2 {
randomLabel.textColor = UIColor.purpleColor()
}
else if randomEight == 3{
randomLabel.textColor = UIColor.orangeColor()
} else if randomEight == 4 {
randomLabel.textColor = UIColor.blueColor()
}
else {
randomLabel.textColor = UIColor.greenColor()
}
return randomLabel
}
Try this oneliner ;)
randomLabel.textColor = UIColor(red : CGFloat(arc4random_uniform(255)) , green : CGFloat(arc4random_uniform(255)), blue : CGFloat(arc4random_uniform(255)) , alpha : 1)

Resources