基礎控件之UILabel、UIButton、UITextField、UIAlertView、 UIImageView

基礎控件之UILabelUIButtonUITextFieldUIAlertView、UIImageView
 
 UILabel:標籤控件,適合一些短的文本
 UILable繼承於UIView

 //lable對象實例化任何對象都要實例化
 UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, CGRectGetWidth([UIScreen mainScreen].bounds), 50)];
 label.text = @"
我是貴陽學院的優秀畢業生,我是貴陽學院的優秀畢業生";
 label.textAlignment = NSTextAlignmentCenter;
 label.textColor = [UIColor brownColor];
//  設置字體大小
 label.font = [UIFont systemFontOfSize:40.0];
//   在加粗的時候同時設置字體大小
    lable.
font= [UIFontboldSystemFontOfSize:48];
//   在設置斜體的同時設置字體大寫
    lable.font= [UIFontitalicSystemFontOfSize:36];
//   設置陰影顏色
 label.shadowColor = [UIColor lightGrayColor];
//   設置陰影偏移量
 label.shadowOffset = CGSizeMake(0, -2);
// 給內容設置行數 0代表自適應行數,非0是幾行就是幾行
 //    label.numberOfLines = 2;
//   自適應字體 從而讓內容儘量顯示一行
 label.adjustsFontSizeToFitWidth = YES;  
 [self.view addSubview:label];
 
 
 UIButton
:按鈕點擊按鈕會觸發事件
 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];//
初始化button設定button的類型
 button.frame = CGRectMake(100, 100, 100, 40);//
設置座標
 button.backgroundColor = [UIColor grayColor];//
設置背景顏色
 button.showsTouchWhenHighlighted = YES;//
當點擊的時候高亮
 [button setTitle:@"TickMe" forState:UIControlStateNormal];
 [button addTarget:self action:@selector(tickMeDoIt) forControlEvents:UIControlEventTouchUpInside];//
設置按鈕什麼狀態下會觸發,觸發調用什麼事件
 [self.view addSubview:button];//
添加按鈕到父視圖
 
 UITextField
是一個輸入控件
 
 UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 40)];//
初始化
 textField.delegate = self;//
添加代理
 textField.backgroundColor = [UIColor grayColor];//
背景顏色
 textField.BorderStyle= UITextBorderStyleLine; //
外框類型
 textField.placeholder = @"
請輸入";//默認的佔位文字
 textField.font = [UIFont systemFontOfSize:20];//
設置字號
 textField.secureTextEntry = YES; //
密碼
 textField.minimumFontSize = 1.0;//
允許調整字體最小的字號
 textField.adjustsFontSizeToFitWidth = YES;//
允許根據輸入框寬度調整字體
 textField.returnKeyType = UIReturnKeyDone;//return
鍵的字樣
 textField.clearButtonMode = UITextFieldViewModeWhileEditing; //
編輯時會出現個清空X
 [self.view addSubview:textField];//
添加到父視圖
 
 UIAlertView
是一個提示或警告的彈出窗口
 
 UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"
提示" message:@"密碼錯誤" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil];//初始化彈出窗口並賦值
 [alertView show];//alertView顯示

//  UIImageView用來顯示圖片
   
UIImageView *imView = [[UIImageViewalloc]init];
//   如果圖片名是png格式的圖片名不需要加格式,否則需要加
//    imView.image = [UIImage imageNamed:@"1.tiff"];
   
    imView.
frame= CGRectMake(80,100,300,300);
    [
self.windowaddSubview:imView];
   
//   創建幀動畫四要素
//    1.設置間隔時間
//    2.準備圖片素材
//    3.設置重複次數
//    4.開始動畫
//   animationDuration設置動畫的時間間隔
    imView.
animationDuration= 1;
//    animationImages重獲動畫
   
UIImage *img1 = [UIImageimageNamed:@"1.tiff"];
   
UIImage *img2 = [UIImageimageNamed:@"2.tiff"];
    
UIImage *img3 = [UIImageimageNamed:@"3.tiff"];
    
UIImage *img4 = [UIImageimageNamed:@"4.tiff"];
   
NSArray *array = @[img1,img2,img3,img4];
//   給幀動畫準備素材
    imView.
animationImages= array;
//   給動畫設置重複次數 使用0無限次循環
//    NSNotFound無限大
    imView.
animationRepeatCount= NSNotFound;
//   動畫開始
//   在某個方向上讓圖片自動適應 已達到最好看的效果
    imView.
contentMode= UIViewContentModeScaleAspectFill;
//
    imView.
contentMode=
   
UIViewContentModeScaleToFill;
    [imView
startAnimating];
//   結束
//    [imView stopAnimating];
   
   
//   延遲多少秒後執行響應的方法
//   selector聲明的方法一定要實現,否則會奔潰
    [
selfperformSelector:@selector(start)withObject:nilafterDelay:5];
//   宏定義
   
//    UIScreen指的是屏幕,能幫助我們獲取到各種屏幕的寬和高
    NSLog(@"%f",[UIScreenmainScreen].bounds.size.height);
發佈了37 篇原創文章 · 獲贊 3 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章