輸⼊控制
外觀控制
UITextField *text= [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
//字體顏色
text.backgroundColor = [UIColor clearColor];
text.textColor = [UIColor tangerineColor];
// 對齊方式
text.textAlignment = NSTextAlignmentLeft;
//字體大小
text.font = [UIFont systemFontOfSize:20];
//佔位字
text.placeholder = @"請輸入";
//邊框格式
text.borderStyle = UITextBorderStyleRoundedRect;
//清楚按鈕 默認NO
text.clearButtonMode = UITextFieldViewModeWhileEditing;
// 是否允許輸入
text.enabled = YES;
// 是否開始輸入的時候清空輸入框內容
text.clearsOnBeginEditing = YES;
//密文輸入
text.secureTextEntry = YES;
// 彈出鍵盤類型
// text.keyboardType = UIKeyboardTypeNumberPad;
// return設置
text.returnKeyType = UIReturnKeyNext;
// UIView *inview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 300)];
// inview.backgroundColor = [UIColor qianweise];
// //自定義鍵盤
// text.inputView = inview;
//
// UIView *inview1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
// inview1.backgroundColor = [UIColor qianweise];
// //輔助視圖
// text.inputAccessoryView = inview1;
// [inview1 release];
//輸入左視圖
// text.leftView = inview;
// text.leftViewMode = UITextFieldViewModeAlways;
// [inview release];
// 設置代理(方法在那裏實現的 就把誰設置爲代理)
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
// 代理可以有很多個點那個那個就是textfield
textField.backgroundColor = [UIColor colorWithRed:arc4random()%255/256.0 green:arc4random()%255/256.0 blue:arc4random()%255/256.0 alpha:1];
// 鍵盤迴收 取消第一響應者
[textField resignFirstResponder];
return YES;
外觀控制
b.frame = CGRectMake(100, 100, 100, 100);
b.backgroundColor = [UIColor clearColor];
//設置標題
[b setTitle:@"普通" forState:(UIControlStateNormal)];
[b setTitle:@"高亮" forState:(UIControlStateHighlighted)];
[b setTitle:@"選中" forState:(UIControlStateSelected)];
[b setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[b setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
[b setTitleColor:[UIColor blueColor] forState:UIControlStateSelected];
[b addTarget:self action:@selector(button:) forControlEvents:(UIControlEventTouchUpInside)];
// 如果不是png格式的圖片加上後綴
[b setBackgroundImage:[UIImage imageNamed:@"Normal.png"] forState:UIControlStateNormal];
[b setBackgroundImage:[UIImage imageNamed:@"Highlighted.png"] forState:UIControlStateHighlighted];
[b setBackgroundImage:[UIImage imageNamed:@"Selected.png"] forState:UIControlStateSelected];
{
button.selected = !button.selected;
// button.backgroundColor = [UIColor colorWithRed:arc4random()%255/256.0 green:arc4random()%255/256.0 blue:arc4random()%255/256.0 alpha:1];
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
// _FUNCION_打印 調用了那個方法
// _LINE_ 打印 這個方法在多少行
NSLog(@"程序小退");
NSLog(@"%s %d", __FUNCTION__,__LINE__);
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
NSLog(@"程序進入後臺");
NSLog(@"%s %d", __FUNCTION__,__LINE__);
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
NSLog(@"程序進入前臺");
NSLog(@"%s %d", __FUNCTION__,__LINE__);
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
NSLog(@"程序激活");
NSLog(@"%s %d", __FUNCTION__,__LINE__);
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
NSLog(@"程序意外退出");
NSLog(@"%s %d", __FUNCTION__,__LINE__);
// 意外退出
}
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
NSLog(@"內存警告是會觸發");