First, compare the Viewcontroller as the root of the navigation to try the controller,
Methods of Object-c
szmyviewcontroller *mvc = [[szmyviewcontrolleralloc] init];
uinavigationcontroller *nav = [[uinavigationcontrolleralloc] Initwithrootviewcontroller : MVC];
self. window . Rootviewcontroller = nav;
Swift's approach
var viewcontroller = viewcontroller();
var nav = uinavigationcontroller(rootviewcontroller:viewcontroller);
self. Window!. Rootviewcontroller = nav;
Here's a look at the UI section: a comparison between the two
1-1, the use of the original UIView
UIView *myview = [[UIViewalloc] initwithframe:cgrectmake (0.0, 100.0, 200.0, 200.0)];
MyView. backgroundcolor = [uicolor colorwithred: 155/255.0 green: 155/255.0 Blue : 155/255.0 Alpha: 1.0];
[Self. View addsubview: MyView];
1-2. Use of Swift's UIView
var myView = UIView(frame:cgrectmake(0.0, 100.0, 200.0, 200.0))
MyView. backgroundcolor = uicolor(red:155/255.0, green:155/255.0, blue:155/255.0, alpha:1.0);
Self. View. Addsubview (MyView)
2-1 use of the original Uilabel
UILabel *mylabel= [[UILabel alloc] initwithframe:cgrectmake(0.0, 100.0 , 200.0, 200.0)];
MyLabel. backgroundcolor = [uicolor colorwithred: 155/255.0 green: 155/255.0 Blue : 155/255.0 Alpha: 1.0];
MyLabel. text = @ " original UILabel";
// set Text size
MyLabel. Font = [uifontsystemfontofsize:];
// Set the color of text
MyLabel. TextColor = [uicolorredcolor];
// Set the alignment of text
MyLabel. TextAlignment = nstextalignmentcenter;
MyLabel. Linebreakmode = nslinebreakbycharwrapping;
[Self. View addsubview: MyLabel];
The use of 2-2swift's Uilabel
var myLabel = UILabel(frame:cgrectmake(0.0, 100.0, 200.0, 200.0))
MyLabel. backgroundcolor = uicolor(red:155/255.0, green:155/255.0, blue:155/255.0, alpha:1.0);
MyLabel. text = "Swift 's UILabel";
// Set the size of the text
MyLabel. font = uifont. Systemfontofsize (30);
// Set text color
MyLabel. textcolor = uicolor. Redcolor ();
// Set the alignment of text
MyLabel. TextAlignment = nstextalignment. Center;
MyLabel. Linebreakmode = nslinebreakmode. Bycharwrapping;
Self. View. Addsubview (MyLabel)
3-1 use of the original UIButton
UIButton *mybtn = [uibuttonbuttonwithtype:uibuttontypecustom];
Mybtn. tag= 110;
mybtn. BackgroundColor = [uicolorredcolor];
[mybtn addTarget:self action:@selector(mybtnselector:) forcontrolevents:uicontroleventtouchupinside];
[mybtn settitle:@ " normal "forstate:uicontrolstatenormal];
[mybtn settitle:@ " highlight "forstate: Uicontrolstatehighlighted];
[Self. View addsubview: mybtn];
-(void) Mybtnselector: (UIButton *) btn{
NSLog (@ " button's tag value is ==%i", Btn.tag);
}
The use of 3-2swift's UIButton
var mybtn = UIButton. Buttonwithtype (uibuttontype. Custom) as? UIButton;
mybtn!. frame = CGRectMake (0.0, 100.0, 200.0, 200.0);
// Set the tag value of the button
mybtn!. tag= 110;
// Set background color
mybtn!. backgroundcolor = uicolor. Greencolor ();
// set the title and status of the normal button
Mybtn?. Settitle (" normal " , forstate: uicontrolstate. Normal)
Mybtn?. Settitle (" highlight " , forstate:uicontrolstate. highlighted);
// Set button's Click event button
Mybtn?. AddTarget (Self, Action:"Mybtnselector:", forControlEvents: uicontrolevents. Touchupinside);
Self. View. Addsubview (MYBTN);
//btn button's Click event
func mybtnselector (sender:UIButton!) {
let btnindex=sender!. tag;
println (" the tag value of the button is =%i", Btnindex);
}