LET constant
Var variable
. DynamicType types
Print (a,b,terminator: ";") End identifier;, default is line break
Sizeof (Type)
Type. Min type. Max gets the maximum and minimum values for the type
string interpolation \ (... Can be operated as a whole)
Var str = "123"
Str.startindex->0
Str.endindex->2
String length use the String.characters.count property to calculate
Var Onearrar = array<int> ()
Var Onearrar = [Int] ()
Var Onearrar = Int, [0,0,0]
Var Onearray = [0,0,0]
Var Onearray = Twoarray + Threearray
Access
ONEARRAY[0]
Add to
Onearray.append (40)
Onearray + = [50,60]
Onearray.insert (70,atindex:0) is added before any valid index
Onearray.removeatindex (0) Delete the value on the index
Unordered set set: Stores the same type of unordered, non-repeating, element must be hashcode
have their own 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) intersection
Let Res2 = Seta.union (SETB) and set
Dictionary Dictionary Key-value pairs
Tuole Ganso to synthesize multiple values into a composite value, the values within the progenitor can be arbitrary, different, or identical
Let Dict1 = dictionary<int,int> ()
Let Dict1 = [Int,int] ()
Var lessondict: [string:string] = ["1": "One", "2", "one"]
lessondict["1"]
Lessondict. ["3"] = "three" key if it does not exist, it will add the key-value.
Delete
Lessondict.removevalueforkey ("1")
lessondict["1"] = Nil
Traverse
for (Key,vlaue) in lessondict{
Print (Key,vale)
}
Tupe Ganso
Let Mytuple = ("1", "2")
Let (lessonindex,lessonname) = Mytuple decomposition meta-ancestor
Mytuple.0 gets to the first element
Interval operator
1 ... 5
1..<5
Optional
Type: Contains two states, has a value, or is null nil
var age:optional<int> <==> var age:int?
Let I:int? =20
Function
Func function name (parameter name: argument type), return value type {
}
Call function, multiple parameters, need to take the formal parameter name
Add (1,num2:2)
Func say (person person)
The function type is determined by the parameter type and the return value type
Define a function type
Var func = Addfunc (int,int)->int
function type as parameter type
Closure self-contained function code block, function is a closure
Closures also have an expression called closure
{(parameter type) –> return type in
}
Let add = {(A:int,b:int), Int in return a + b}
{(a:int,b:int)-Int in return a + B} anonymous function
{$ + $}
Trailing closures
The
UILabel
Program entry is application in the didifinishlaunchingwithoptions loop;
Launchscreen.storyboard preload screen
Let Label:uilabel = UILabel (Frame:cgrectmake (x,y,leng,width))
Label.text = "is a Label"
Label.font = Uifont ()
Lab El.textcolor = Uicolor ()
Label.backgroundcolor = ...
Label.textalignment = nstextalignment.center
Label.shadowcolor = Uicollor .... Set Shadow
Label.shadowoffset = Cgsziemake (10,10) set offset
Label.numberoflines = 2 Set the number of lines to 0 for infinite lines
Self.view.addSubview (label) is loaded onto the view
Uibotton
Let Button:uibutton UIButton (type:UIButtonType.System) Sets the button type enum many types
Custom Customization No type
System standard Type
Infodark Details Style
Contactadd Adding a type
Button.frame=cgrectmake (10,10,100,100)
Add Event
Button.addtarget (Selft,action:selector ("click"), ForControlEvents:UIControlEvents.TouchUpInside)
Button.contentedgeinsets = Uiedgeinsetsmake ( -10,-10,0,0) sets the offset of the content
Button.setimage (UIImage (named:1.jpg), forState:UIControlState.Normal)//Parallel (picture-text)
Button.setbackgroundimage (UIImage (named:1.jpg), forState:UIControlState.Normal)//text will be above the picture
Self.view.addSubview (Button)
Click on the function to execute
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//Set highlight picture
imageview.highlighted = true//is set to the highlighted state
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]//sets an animated array of ImageView
Imageview.animationrepeatcount = 0 Set the number of animations played 0 unlimited
Imageview.animationduration = 3 Set a play time of 3 seconds
Imageview.startanimating () Start playing the animation
Set.view.addSubview (ImageView)
Layer Property
imageview.layer.maskstobounds=true//Setting rounded corners
ImageView.layer.cornerRadius = 50
ImageView.layer.borderWidth = 2 Set border
ImageView.layer.borderColor = Uicolor.greencolor ()
ImageView.layer.shadowColor = ... Set Shadow
ImageView.layer.shadowOffset = Cgsizemake (10,10)
imageView.layer.shadowOpacity = 1; Set opaque
Uisearchbar
Let Searchbar:uisearchbar = Uisearchbar ()
Searchbar.placeholder = "Please enter keywords"//set default prompt
Searcbar.text = "Sword Saint"//Set Default text
Searchbar.barstyle = Uibarstyle. () Setting Style
Searchbar.prompt = "" Background text (title function)
Searchbar.showsbookmarkbutton=true Setting the Function button display or not
Searchbar.tintcolor setting the cursor and other rendering colors
Searchbar.bartintcolor Setting the search box background color
HTTP://WWW.MAIZIEDU.COM/COURSE/710-10351/not
Uiswitch
Myswitch.thumbtintcolor ... Set the color of the slider
Add Event
Uisegementcontrol
Let Seg:uisegementcontrol = Uisegementcontrol ()
Seg.insertsegmentwithtile ("First button", atindex:0,animated:true) set up the segment controller
Seg.addtarget (Selft,action:selector ("clickseg:"), ForControleEvents:UIControlEvents.ValueChange)
Seg.momentary = False true to set whether to keep the selection state
Touchesbegan ()
Func clickseg (Seg:uisegementcontrol) {
}
Bringsubviewtofront (Viewblue) Put a view on the top
iOS Basic UI