溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

ios 基礎(chǔ)UI

發(fā)布時間:2020-07-29 18:10:07 來源:網(wǎng)絡(luò) 閱讀:515 作者:cnslp 欄目:移動開發(fā)

Let常量
Var 變量
.dynamicType 類型
Print(a,b,terminator:”;”)結(jié)尾符為;,默認(rèn)是換行

Sizeof(Type)
類型.min 類型.max 獲取到類型最大和最小的值

字符串插值 \(…可以進行操作,作為整體)

Var str = “123”
Str.startIndex ->0
Str.endIndex ->2

字符串長度使用 String.characters.count 屬性來計算

Var oneArrar = Array<Int>()
Var oneArrar = [Int]()
Var oneArrar = Int -> [0,0,0]
Var oneArray = [0,0,0]
Var oneArray = twoArray + threeArray
訪問
oneArray[0]
添加
oneArray.append(40)
oneArray += [50,60]
oneArray.insert(70,atIndex:0) 在任意有效索引前面添加
oneArray.removeAtIndex(0) 刪除索引上的值

無序集set:存儲相同類型的無序、不重復(fù),元素必須是hashcode
有自身的hashValue
let myset = Set<String>()
let myset = Set<String>([“1”,”2”,”3”])
let myset = Set([“1”,”2”,”3”]) -> {“1”,”2”,”3”}
let myset = Set([“1”,”2”,”1”]) ->{“1”,”2”}

myset.insert(“sfdf”)
myset.remove(“sfdf”)
for item in myset.sort(){
print(item)
}
Myset.count
Myset.isEmpty
Contians(sfdf)
Let res = seta.intersect(setb) 交集
Let res2 = seta.union(setb) 并集

Dictionary 字典 鍵值對
Tuole 元祖 把多個值合成一個復(fù)合值,元祖內(nèi)的值可以任意的,可以不同或相同

Let dict1 = Dictionary<Int,Int>()
Let dict1 = [Int,Int]()
Var lessonDict : [String:String] = [“1”:”one”,”2”,”two”]
lessonDict[“1”]
lessonDict.[“3”] = “three” key如果不存在就會把key-value添加進去
刪除
lessonDict.removeValueForKey(“1”)
lessonDict[“1”] = nil
遍歷
For(key,vlaue) in lessonDict{
Print (key,vale)
}

Tupe 元祖
Let mytuple = (“1”,”2”)
Let (lessonIndex,lessonName) = mytuple 分解元祖
Mytuple.0 獲取到第一個元素

區(qū)間運算符
1…5
1..<5

Optional
類型:包含兩種狀態(tài),有某個值,或者為空nil
Var age : Optional<Int> <==> var age : Int?
let I : Int? =20

函數(shù)
func 函數(shù)名(參數(shù)名:參數(shù)類型) -> 返回值類型 {

}

調(diào)用函數(shù),多個形參的時候,需要帶上形參名
add(1,num2: 2)

func say(person person)

函數(shù)類型由參數(shù)類型和返回值類型確定
定義一個函數(shù)類型
Var func = addfunc (Int,Int)->Int

函數(shù)類型作為參數(shù)類型

閉包自包含的函數(shù)代碼塊,函數(shù)是一種閉包
閉包還有一種叫閉包表達式
{(參數(shù)類型) –>返回類型 in

}

let add = {(a : Int,b : Int) -> Int in return a + b}
{(a : Int,b : Int) -> Int in return a + b} 匿名函數(shù)
{$0 + $1}

尾隨閉包

UILabel
程序入口是application的didiFinishLaunchingWithOptions里循環(huán)進行的;
LaunchScreen.storyboard預(yù)加載畫面
Let label : UILabel = UILabel(frame : CGRectMake(x,y,leng,width))
Label.text = “is a label”
Label.font = UIFont()
Label.textColor = UIColor()
Label.backgroundColor = …
Label.textAlignment = NSTextAlignment.Center
Label.shadowColor = UICollor…. 設(shè)置陰影
Label.shadowOffset = CGSzieMake(10,10) 設(shè)置偏移量
Label.numberOfLines = 2 設(shè)置行數(shù) 設(shè)置為0為無限行
Self.view.addSubview(label)加載到視圖上

UIBotton
Let button:UIButton UIButton(type: UIButtonType.System) 設(shè)置button類型 枚舉很多類型
Custom 自定義無類型
System 系統(tǒng)標(biāo)準(zhǔn)類型
InfoDark 詳情樣式
ContactAdd 添加類型
Button.frame=CGRectMake(10,10,100,100)
//添加事件
Button.addTarget(selft,action:Selector(“click”),forControlEvents:UIControlEvents.TouchUpInside)
Button.contentEdgeInsets = UIEdgeInsetsMake(-10,-10,0,0) 設(shè)置內(nèi)容的偏移量
Button.setImage(UIImage(named:1.jpg),forState:UIControlState.Normal) //并行 (圖片-文字)
Button.setBackgroundImage(UIImage(named:1.jpg),forState:UIControlState.Normal)//文字會在圖片上面

Self.view.addSubview(button)

//點擊執(zhí)行的函數(shù)
Func click(btn:UIButton){
Btn.backgroundColor = UIColor(red : (CGFloat)(random()%255)/255,green:34,blue:34,alpha:1)
}

UIImageView
Let imageView:UIImageView = UIImageView(frame:CGRectMake(100,100,100,100))
imageView.image = UIImage(named: “1.png”)
imageView.hightlightedImage //設(shè)置高亮圖片
imageView.highlighted = true//設(shè)置為高亮狀態(tài)
var array:Array<UIImage!> = Array()
for var i=0;i<3;i++{
let image:UIImage? = UIImage(named: String(format:”%d.png”,i))
array.append(image!)
}
imageView.animationImages = array as ? [UIImage]//設(shè)置imageView的動畫數(shù)組
imageView.animationRepeatCount = 0 設(shè)置動畫的播放次數(shù) 0 無限
imageView.animationDuration = 3 設(shè)置一輪播放時間3秒
imageView.startAnimating() 開始播放動畫
set.view.addSubview(imageView)

layer屬性
imageView.layer.masksToBounds=true//設(shè)置圓角
imageView.layer.cornerRadius = 50
imageView.layer.borderWidth = 2 設(shè)置邊框
imageView.layer.borderColor = UIColor.greenColor()
imageView.layer.shadowColor = … 設(shè)置陰影
imageView.layer.shadowOffset = CGSizeMake(10,10)
imageView.layer.shadowOpacity =1; 設(shè)置不透明

UISearchBar
Let searchBar:UISearchBar = UISearchBar()
searchBar.placeholder = “請輸入關(guān)鍵字” // 設(shè)置默認(rèn)提示語
searcBar.text = “劍圣” //設(shè)置默認(rèn)文字
searchBar.barStyle = UIBarStyle.()設(shè)置風(fēng)格
searchBar.prompt = “” 背景文字(title作用)
searchBar.showsBookmarkButton=true 設(shè)置相應(yīng)功能按鈕的顯示與否
searchBar.tintColor 設(shè)置光標(biāo)等渲染顏色
searchBar.barTintColor 設(shè)置搜索框背景顏色

http://www.maiziedu.com/course/710-10351/ 未

UISwitch
mySwitch.thumbTintColor… 設(shè)置滑塊的顏色
添加事件

UISegementControl
Let seg: UISegementControl = UISegementControl()
Seg.insertSegmentWithTile(“第一個按鈕”,atIndex:0,animated:true)設(shè)置分段控制器
Seg.addTarget(selft,action: Selector(“clickSeg:”),forControleEvents:UIControlEvents.ValueChange)
Seg.momentary = false true 設(shè)置是否保持選擇狀態(tài)

touchesBegan()

func clickSeg(seg: UISegementControl){

}

bringSubviewToFront(viewBlue) 把某個view放在最上面

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI