您的位置:首页 > 博客中心 > APP开发 >

ios 基础UI

时间:2022-03-12 15:28

Let常量
Var 变量
.dynamicType 类型
Print(a,b,terminator:”;”)结尾符为;,默认是换行

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 = -> [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:存储相同类型的无序、不重复,元素必须是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 元祖 把多个值合成一个复合值,元祖内的值可以任意的,可以不同或相同

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 获取到第一个元素

区间运算符
1…5
1..<5

Optional
类型:包含两种状态,有某个值,或者为空nil
Var age : Optional<Int> <==> var age : Int?
let I : Int? =20

函数
func 函数名(参数名:参数类型) -> 返回值类型 {

}

调用函数,多个形参的时候,需要带上形参名
add(1,num2: 2)

func say(person person)

函数类型由参数类型和返回值类型确定
定义一个函数类型
Var func = addfunc (Int,Int)->Int

函数类型作为参数类型

闭包自包含的函数代码块,函数是一种闭包
闭包还有一种叫闭包表达式
{(参数类型) –>返回类型 in

}

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

尾随闭包

UILabel
程序入口是application的didiFinishLaunchingWithOptions里循环进行的;
LaunchScreen.storyboard预加载画面
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…. 设置阴影
Label.shadowOffset = CGSzieMake(10,10) 设置偏移量
Label.numberOfLines = 2 设置行数 设置为0为无限行
Self.view.addSubview(label)加载到视图上

UIBotton
Let button:UIButton UIButton(type: UIButtonType.System) 设置button类型 枚举很多类型
Custom 自定义无类型
System 系统标准类型
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) 设置内容的偏移量
Button.setImage(UIImage(named:1.jpg),forState:UIControlState.Normal) //并行 (图片-文字)
Button.setBackgroundImage(UIImage(named:1.jpg),forState:UIControlState.Normal)//文字会在图片上面

Self.view.addSubview(button)

//点击执行的函数
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 //设置高亮图片
imageView.highlighted = true//设置为高亮状态
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]//设置imageView的动画数组
imageView.animationRepeatCount = 0 设置动画的播放次数 0 无限
imageView.animationDuration = 3 设置一轮播放时间3秒
imageView.startAnimating() 开始播放动画
set.view.addSubview(imageView)

layer属性
imageView.layer.masksToBounds=true//设置圆角
imageView.layer.cornerRadius = 50
imageView.layer.borderWidth = 2 设置边框
imageView.layer.borderColor = UIColor.greenColor()
imageView.layer.shadowColor = … 设置阴影
imageView.layer.shadowOffset = CGSizeMake(10,10)
imageView.layer.shadowOpacity =1; 设置不透明

UISearchBar
Let searchBar:UISearchBar = UISearchBar()
searchBar.placeholder = “请输入关键字” // 设置默认提示语
searcBar.text = “剑圣” //设置默认文字
searchBar.barStyle = UIBarStyle.()设置风格
searchBar.prompt = “” 背景文字(title作用)
searchBar.showsBookmarkButton=true 设置相应功能按钮的显示与否
searchBar.tintColor 设置光标等渲染颜色
searchBar.barTintColor 设置搜索框背景颜色

UISwitch
mySwitch.thumbTintColor… 设置滑块的颜色
添加事件

UISegementControl
Let seg: UISegementControl = UISegementControl()
Seg.insertSegmentWithTile(“第一个按钮”,atIndex:0,animated:true)设置分段控制器
Seg.addTarget(selft,action: Selector(“clickSeg:”),forControleEvents:UIControlEvents.ValueChange)
Seg.momentary = false true 设置是否保持选择状态

touchesBegan()

func clickSeg(seg: UISegementControl){

}

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

相关推荐

电脑软件

本类排行

今日推荐

热门手游