objective-III
return UIApplicationMain(argc, argv, nil,NSStringFromClass([AppDelegateclass]));//直接跳轉到AppDelegate類,因此我們一般在AppDelegate中進行設計
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]]autorelease];//當前窗口的大小
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];//當前窗口的顏色
// self.window.backgroundColor=[UIColor yellowColor];
FirstViewController *first=[[FirstViewControlleralloc]init];//創建一個窗口對象
self.window.rootViewController=first;//將創建好的first頁面作爲第一視圖進行展示
[self.windowmakeKeyAndVisible];//顯示窗口
returnYES;
}
- (void)viewDidLoad//當前頁面加載的時候調用的方法。
{//一般寫組建的創建和屬性、變量的初始化
[superviewDidLoad];
//用代碼的形式創建組件
//1、實例化一個對象
UILabel *la=[[UILabelalloc]init];
//2、設置組件的相關屬性 [整個頁面的座標系從左上角開始(往下x增大,往右x增大)]
la.frame=CGRectMake(20,30, 280, 50);//座標和組件的大小 四個參數值分別爲:x值,y值,組件寬度,組件高度
la.text=@"濱州學院內部系統";//標籤要顯示的內容
la.textAlignment=NSTextAlignmentCenter;//居中對齊
la.backgroundColor=[UIColorclearColor];//背景顏色爲透明色
la.textColor=[UIColorredColor];//字體顏色
la.font=[UIFontsystemFontOfSize:30];//字體大小
//3、將這個組件加載到當前視圖
[self.viewaddSubview:la];
// Do any additional setup after loading the view from its nib.
}
//-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event//點擊屏幕取消時調用的方法,即當你正在點擊屏幕,此時來電話了所觸發的方法
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event//點擊屏幕時觸發的事件
{
UITouch *t=[touches anyObject];//得到點擊屏幕的位置
if (![t.viewisMemberOfClass:[UITextFieldclass]]) {//t.view isMemberOfClass:]判斷點擊的對象是不是輸入框 UITextField class:不是輸入框
//如果點擊的組件不是輸入框,就讓鍵盤退下去
[self.uerNameresignFirstResponder];//取消掉userName的第一相應者(就是讓userName組件失去焦點,不再屏幕上作爲第一焦點出現)
//resignFirstResponder:取消第一相應者(即焦點)
[self.passWordresignFirstResponder];//同上
}
}
II、實現頁面跳轉的效果
同樣在.m文件中 代碼如下
//登陸按鈕的監聽事件
- (IBAction)login:(id)sender {
//如果用戶名爲admin,密碼爲123則進行跳轉,跳轉到second頁面
//self:當前對象 self.uerName.text:取得當前頁面的名爲uerName的輸入框中的輸入的字符
if ([self.uerName.textisEqualToString:@"admin"]&&[self.passWord.textisEqualToString:@"123"])
{
SecondViewController *second=[[SecondViewControlleralloc]init];//創建第二個頁面
//設置頁面跳轉的動畫效果
second.modalTransitionStyle=UIModalTransitionStyleCoverVertical;//設置頁面跳轉的動畫效果
//modalTransitionStyle的值爲一個枚舉類型其值有如下四個:
// UIModalTransitionStyleCoverVertical = 0,//從下往上推送
// UIModalTransitionStyleFlipHorizontal,//翻轉
// UIModalTransitionStyleCrossDissolve,//漸變
// UIModalTransitionStylePartialCurl,//半翻頁
[selfpresentViewController:secondanimated:YEScompletion:nil];//second爲將要跳轉的頁面 animated:是否要有動畫效果 completion:傳遞的參數
}
}
在自定義的SecondViewController頁面的.m文件中添加button按鈕,然後設置單擊監聽事件,單擊時彈出提示框
在SecondViewController自定義界面的.m文件中代碼如下:
- (void)viewDidLoad
{
[superviewDidLoad];
//設置提示框組件
//第一步、創建一個圓角按鈕
UIButton *but=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];
//第二步、設置組件屬性
[but setTitle:@"點擊這裏" forState:UIControlStateNormal];//在普通狀態下得title
[but addTarget:selfaction:@selector(showAlert)forControlEvents:UIControlEventTouchUpInside];//添加監聽事件
but.frame=CGRectMake(120,100, 80, 40);//座標大小
//第三步將組件添加到當前視圖上
[self.viewaddSubview:but];
// Do any additional setup after loading the view from its nib.
}
//彈出提示函數 與調用組件中的selector函數名必須保持一致
-(void)showAlert
{
//UIAlertView 爲提示框類 創建一個提示框組件
UIAlertView *alert=[[UIAlertViewalloc]initWithTitle:@"提示"message:@"你太聰明瞭,都寫對了" delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"確定",nil];
[alert show];//彈出提示框
}