/**
1. OC [UIView alloc] Initwithxxx:]
Swift UIView (XXX:)
Class name () = = Alloc/init equivalent
2. Class methods
OC [Uicolor Redcolor]
Swift uicolor.red
3. To access the properties of the current object, you can not use ' self. '
Recommendation: None, at the time of the compiler prompt, in addition, will have a better understanding of the ' context '
Reason: Closures (similar to block in OC) require the use of ' self. '
4. No '; '
The purpose of the '; ' is to split the statement, in Swift, which is not required by default. Multiple statements are required on a single line.
5. Enumeration type
OC Uibuttontypecontactadd
Swift. Contactadd
6. Monitoring methods
OC @selector
Swift #selector ()--3.0 There are no parameters do not need to add ': ', Debugging Plus ': ' is also possible, specifically see the following demo
"ClickMe", "ClickMe:"--2.0
7. Add document Comment shortcut key option + cmd +/
8. Display color panel colour + carriage return
9. Pre-compilation instructions are canceled
*/
Class Viewcontroller:uiviewcontroller
{
MARK:-View life cycle
MARK: View loading complete
Override Func Viewdidload ()
{
Super.viewdidload ()
multiple statements need '; ' In one line Separated. A single statement is not required by default '; '
Let A = 10; Let B = 20
Print ("a=\ (a); B=\ (b) ")
1. Create a View
Let V = UIView (Frame:cgrect (x:20, y:40, width:100, height:200))
Set Background color
V.backgroundcolor = uicolor.red//TODO: The new color should be set
V.backgroundcolor = #colorLiteral (red:0.7450980544, green:0.1568627506, blue:0.07450980693, alpha:1)
Add to Current View
View.addsubview (v)
2. Create a button
Let btn = UIButton (type:. Contactadd);
Btn.frame = CGRect (x:0, y:0, width:60, height:30)
Btn.center = Cgpoint (x:v.frame.size.width * 0.5, Y:v.frame.size.height * 0.5)
Method ClickMe the notation without parameters
Btn.addtarget (Self, Action: #selector (ClickMe), for:. Touchupinside)
Method ClickMe (Btn:uibutton) with parameters of the following two kinds of notation can be, debugging no problem found
Btn.addtarget (Self, Action: #selector (ClickMe1 (btn:)), for:. Touchupinside)
Btn.addtarget (Self, Action: #selector (CLICKME1), for:. Touchupinside);
V.addsubview (BTN)
Let LV = Uiimageview (Image: #imageLiteral (resourcename: "contact_checked")); Fixme: The image should be changed
View.addsubview (LV)
}
Func ClickMe () ()
{
Print (#function)
Print ("hehe")
}
Func clickMe1 (Btn:uibutton) ()
{
Print (#function)
Print ("hehe")
Print ("btn=\ (BTN)")
}
}
Swift learns the first demo, explaining some of the common knowledge points