欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

swift實(shí)現(xiàn)隨機(jī)背景色

 更新時(shí)間:2022年01月26日 10:44:50   作者:mjbaishiyun  
這篇文章主要為大家詳細(xì)介紹了swift實(shí)現(xiàn)隨機(jī)背景色,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了swift實(shí)現(xiàn)隨機(jī)背景色的具體代碼,供大家參考,具體內(nèi)容如下

//
// ?ViewController.swift
// ?網(wǎng)絡(luò)獲取圖片
//
// ?Created by 悅兌科技 on 15/1/27.
// ?Copyright (c) 2015年 BSY. All rights reserved.
//


import UIKit

class ViewController: UIViewController {


? ? override func viewDidLoad() {
? ? ? ? super.viewDidLoad()
? ? ? ? [self .addButton()] ? ? ?

? ? }

? ?override func viewWillAppear(animated: Bool) {
? ? ? ? super.viewWillAppear(animated) ??

? ? self.view.backgroundColor = UIColor.whiteColor()

? ? }

? ? func addButton()

? ? {

? ? ? ? // 創(chuàng)建button
? ? ? ? var button:UIButton = ?UIButton.buttonWithType(UIButtonType.Custom) as UIButton
? ? ? ? var frame = CGRectMake(100, 100, 100, 100)
? ? ? ? button.frame = frame


? ? ? ? // 設(shè)置字體
? ? ? ? button.setTitle("隨即色", forState: UIControlState.Normal)
? ? ? ? button.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
? ? ? ? button.titleLabel?.font = UIFont(name: "Heiti SC", size: 20)

? ? ? ??

? ? ? ? // 設(shè)置圓形
? ? ? ? self.view.addSubview(button)
? ? ? ? button.layer.borderColor = UIColor.lightGrayColor().CGColor
? ? ? ? button.layer.borderWidth = 2
? ? ? ? button.layer.cornerRadius = 50
? ? ? ? button.layer.backgroundColor = UIColor.whiteColor().CGColor
? ? ? ? [button .addTarget(self, action: "buttonClick", forControlEvents: UIControlEvents.TouchUpInside)]

? ? }

? ? /**
? ? button方法實(shí)現(xiàn)
? ? */

? ? func buttonClick()

? ? {


? ? ? ? /**
? ? ? ? * ?創(chuàng)建顏色
? ? ? ? */
? ? ? ? var color = UIColor(red: 183/255.0, green: 183/255.0, blue: 183/255.0, alpha: 1.0)
? ? ? ? var color1 = UIColor.blueColor()
? ? ? ? var color2 = UIColor.brownColor()
? ? ? ? var color3 = UIColor.yellowColor()
? ? ? ? var color4 = UIColor.orangeColor()
? ? ? ? var color5 = UIColor.blackColor()
? ? ?

? ? ? ? /**

? ? ? ? * ?創(chuàng)建可變數(shù)組并把顏色添加到數(shù)組

? ? ? ? */

? ? ? ? var arrM :NSMutableArray = NSMutableArray()
? ? ? ? arrM.addObject(color)
? ? ? ? arrM.addObject(color1)
? ? ? ? arrM.addObject(color2)
? ? ? ? arrM.addObject(color3)
? ? ? ? arrM.addObject(color4)
? ? ? ? arrM.addObject(color5)

? ? ? ? /**
? ? ? ? * ?把顏色賦值給父控件的view
? ? ? ? */

? ? ? ? self.view.backgroundColor = arrM.objectAtIndex(Int(arc4random_uniform(UInt32(arrM.count)))) as? UIColor

? ? ? ?

? ? }

}

效果:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解Swift中的Characters字符類(lèi)型與String字符串類(lèi)型

    詳解Swift中的Characters字符類(lèi)型與String字符串類(lèi)型

    Swift中的字符串操作相當(dāng)便捷,下面我們來(lái)詳解Swift中的Characters字符類(lèi)型與String字符串類(lèi)型,需要的朋友可以參考下
    2016-06-06
  • Swift使用enum抹平數(shù)組元素差異實(shí)例詳解

    Swift使用enum抹平數(shù)組元素差異實(shí)例詳解

    這篇文章主要為大家介紹了Swift使用enum抹平數(shù)組元素差異實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • 用Swift構(gòu)建一個(gè)簡(jiǎn)單的iOS郵件應(yīng)用的方法

    用Swift構(gòu)建一個(gè)簡(jiǎn)單的iOS郵件應(yīng)用的方法

    這篇文章主要介紹了用Swift構(gòu)建一個(gè)簡(jiǎn)單的iOS郵件應(yīng)用的方法,包括查看和標(biāo)記已讀等基本的郵件應(yīng)用功能,需要的朋友可以參考下
    2015-07-07
  • 升級(jí)到Swift 4.0可能遇到的坑總結(jié)

    升級(jí)到Swift 4.0可能遇到的坑總結(jié)

    這篇文章主要給大家介紹了關(guān)于升級(jí)到Swift 4.0可能遇到的坑的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用swift4具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11
  • SwiftUI 中創(chuàng)建反彈動(dòng)畫(huà)的實(shí)現(xiàn)

    SwiftUI 中創(chuàng)建反彈動(dòng)畫(huà)的實(shí)現(xiàn)

    這篇文章主要介紹了SwiftUI 中創(chuàng)建反彈動(dòng)畫(huà)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • Swift用final關(guān)鍵字來(lái)防止重寫(xiě)

    Swift用final關(guān)鍵字來(lái)防止重寫(xiě)

    final關(guān)鍵字在大多數(shù)的編程語(yǔ)言中都存在,表示不允許對(duì)其修飾的內(nèi)容進(jìn)行繼承或者重新操作。下面通過(guò)實(shí)例代碼給大家介紹swift用final關(guān)鍵字來(lái)防止重寫(xiě)
    2016-12-12
  • swift4.2實(shí)現(xiàn)新聞首頁(yè)導(dǎo)航

    swift4.2實(shí)現(xiàn)新聞首頁(yè)導(dǎo)航

    這篇文章主要為大家詳細(xì)介紹了swift4.2實(shí)現(xiàn)新聞首頁(yè)導(dǎo)航,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • Swift中初始化方法的順序介紹

    Swift中初始化方法的順序介紹

    這篇文章主要介紹了Swift中初始化方法的順序介紹,本文介紹的是了類(lèi)的初始化方法,需要的朋友可以參考下
    2015-01-01
  • Swift 3.1聊天界面鍵盤(pán)效果的實(shí)現(xiàn)詳解

    Swift 3.1聊天界面鍵盤(pán)效果的實(shí)現(xiàn)詳解

    這篇文章主要給大家介紹了Swift 3.1聊天界面鍵盤(pán)效果實(shí)現(xiàn)的相關(guān)資料,文中介紹的非常詳細(xì),相信對(duì)大家的學(xué)習(xí)或者工作具有一定的參考價(jià)值,需要的朋友們下面來(lái)一起看看吧。
    2017-04-04
  • Swift中的可選項(xiàng)Optional解包方式實(shí)現(xiàn)原理

    Swift中的可選項(xiàng)Optional解包方式實(shí)現(xiàn)原理

    這篇文章主要為大家介紹了Swift中的可選項(xiàng)Optional解包方式實(shí)現(xiàn)原理示例分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03

最新評(píng)論