UILabel:顯示文本的控件
UILabel屬性設(shè)置
_label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];//初始化
_label.text = @"用戶名";//要顯示的文本內(nèi)容
_label.textColor = [UIColor redColor];//文本內(nèi)容的顏色
_label.textAlignment = NSTextAlignmentLeft;//文本的對(duì)齊方式(水平方向)
/*對(duì)齊方式有三種:
NSTextAlignmentLeft 居左
NSTextAlignmentCenter 居中
NSTextAlignmentRight 居右
*/
_label.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];//黑色加粗拒担,20號(hào)字體
_label.numberOfLines = 3;//行數(shù) 顯示3行城侧,注意label的高度要能容納3行异剥。如果3行沒能顯示完信息,沒顯示的信息以省略號(hào)代替。
_label.lineBreakMode = NSLineBreakByCharWrapping;//斷行模式 以單詞為單位斷行
_label.shadowColor = [UIColor yellowColor];//陰影顏色
_label.shadowOffset = CGSizeMake(2, 1);//陰影大小 陰影向x正方向偏移2蚕泽,向y正方向偏移1
UITextField :輸入框,是控制文本輸入和顯示的控件
UITextField屬性設(shè)置
_textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 80, 200, 50)];
// _textField.text = @"lanoukeji";//要顯示的文本內(nèi)容
_textField.backgroundColor = [UIColor lightGrayColor];//背景顏色
_textField.textColor = [UIColor greenColor];//文本內(nèi)容的顏色
_textField.textAlignment = NSTextAlignmentCenter;//文本的對(duì)齊方式(水平方向)
/*對(duì)齊方式有三種:
NSTextAlignmentLeft 居左
NSTextAlignmentCenter 居中
NSTextAlignmentRight 居右
*/
_textField.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];//黑體加粗 20號(hào)
_textField.placeholder = @"你好";//占位字符串
_textField.enabled = YES;//是否允許修改
_textField.clearsOnBeginEditing = YES;//是否開始輸入的時(shí)候桥嗤,清空輸入框的內(nèi)容
_textField.secureTextEntry = NO;//是否文字以圓點(diǎn)顯示 YES 為密碼模式 NO為普通模式
// _textField.keyboardType = UIKeyboardTypeNumberPad;//數(shù)字鍵盤
/*鍵盤樣式:
*/
// _textField.returnKeyType = UIReturnKeyGoogle;//鍵盤右下角return按鈕類型(枚舉值)
/*return按鍵類型:
UIReturnKeyDefault,
UIReturnKeyGo,
UIReturnKeyGoogle,
UIReturnKeyJoin,
UIReturnKeyNext,
UIReturnKeyRoute,
UIReturnKeySearch,
UIReturnKeySend,
UIReturnKeyYahoo,
UIReturnKeyDone,
UIReturnKeyEmergencyCall,
UIReturnKeyContinue
*/
// _textField.inputView = myInputView;//自定時(shí)輸入視圖 默認(rèn)是鍵盤=>重寫鍵盤
// _textField.inputAccessoryView = myAccessoryView;//輸入視圖上方的輔助視圖须妻,默認(rèn)是nil
_textField.borderStyle = UITextBorderStyleRoundedRect;//邊框樣式(枚舉值)
/*
UITextBorderStyleNone, //無
UITextBorderStyleLine, 顯示邊框外線條
UITextBorderStyleBezel, 也是線條
UITextBorderStyleRoundedRect 圓角
*/
_textField.clearButtonMode = UITextFieldViewModeAlways;//清除按鈕模式
/*
UITextFieldViewModeNever,
UITextFieldViewModeWhileEditing,
UITextFieldViewModeUnlessEditing,
UITextFieldViewModeAlways
*/
UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
leftView.backgroundColor = [UIColor redColor];
_textField.leftView = leftView;//輸入框左視圖
_textField.leftViewMode = UITextFieldViewModeAlways;//左視圖的顯示模式
/*
UITextFieldViewModeNever,
UITextFieldViewModeWhileEditing,
UITextFieldViewModeUnlessEditing,
UITextFieldViewModeAlways
*/
// _textField.rightView = rightView;//輸入框右視圖
_textField.rightViewMode = UITextFieldViewModeAlways;//右視圖顯示模式
//代理
_textField.delegate = self;
代理方法
//當(dāng)textFiel將要開始編輯的時(shí)候告訴委托人
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
NSLog(@"將要開始編輯");
return YES;
}
//當(dāng)textfield已經(jīng)編輯的時(shí)候告訴委托人
- (void)textFieldDidBeginEditing:(UITextField *)textField {
NSLog(@"已經(jīng)開始編輯");
}
//當(dāng)textField將要完成編輯的時(shí)候告訴委托人
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
NSLog(@"將要完成編輯");
return YES;
}
//當(dāng)textField已經(jīng)完成編輯的時(shí)候告訴委托人
- (void)textFieldDidEndEditing:(UITextField *)textField {
NSLog(@"%@",textField.text);
NSLog(@"已經(jīng)完成編輯");
}
//點(diǎn)擊鍵盤回車按鍵的時(shí)候告訴委托人
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
//取消第一響應(yīng)者
NSLog(@"點(diǎn)擊return");
[self.textField resignFirstResponder];
return YES;
}
UIButton:按鈕
UIbutton屬性
_button = [UIButton buttonWithType:UIButtonTypeSystem];
_button.frame = CGRectMake(20, 150, 100, 40);
_button.backgroundColor = [UIColor yellowColor];//背景顏色
[_button setTitle:@"按鈕" forState:UIControlStateNormal];//設(shè)置指定狀態(tài)下的標(biāo)題
NSString *title = [_button titleForState:UIControlStateNormal];//獲取指定狀態(tài)下的標(biāo)題
NSLog(@"%@", title);
[_button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];//設(shè)置執(zhí)行狀態(tài)下的標(biāo)題顏色
UIColor *titleColor = [_button titleColorForState:UIControlStateNormal];//獲取指定狀態(tài)下的標(biāo)題顏色
NSLog(@"%@", titleColor);
[_button setTitleShadowColor:[UIColor purpleColor] forState:UIControlStateNormal];//設(shè)置指定狀態(tài)下標(biāo)題陰影顏色
UIColor *shadowColor = [_button titleShadowColorForState:UIControlStateNormal];//獲取指定狀態(tài)下標(biāo)題陰影顏色
UIImage *image = [UIImage imageNamed:@"novel"];
[_button setImage:image forState:UIControlStateNormal];//設(shè)置指定狀態(tài)下的前景圖片
NSLog(@"%@",image);
UIImage *imageForNormal =[_button imageForState:UIControlStateNormal];//獲取指定狀態(tài)下的前景圖片
NSLog(@"%@", imageForNormal);
//設(shè)置指定狀態(tài)下的背景圖片
[_button setBackgroundImage:image forState:UIControlStateNormal];
UIImage *imageForBackground = [_button backgroundImageForState:UIControlStateNormal];//獲取指定狀態(tài)下的背景圖片
NSLog(@"%@", imageForBackground);
添加點(diǎn)擊事件
//添加點(diǎn)擊事件
[_button addTarget:self action:@selector(changeColor:) forControlEvents:UIControlEventTouchUpInside];
//移除按鈕的點(diǎn)擊事件
// [_button removeTarget:self action:@selector(changeColor:) forControlEvents:UIControlEventTouchUpInside];
//button回調(diào)方法
- (void)changeColor:(UIButton *)sender {
sender.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:arc4random() % 256 / 255.0];
}
UIImageView:圖片顯示框
UIImageView的屬性
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 200, 100, 100)];
_imageView.backgroundColor = [UIColor lightGrayColor];
NSString *path = [[NSBundle mainBundle] pathForResource:@"footLeft_0" ofType:@"jpg"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
_imageView.image = image;
// [_imageView setImage:image];
動(dòng)畫
//動(dòng)畫
NSMutableArray *imageMArray = [[NSMutableArray alloc] init];//一組動(dòng)態(tài)圖片
for (int i = 0; i < 30; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"footLeft_%d.jpg", i]];
[imageMArray addObject:image];
}
_imageView.animationImages = imageMArray;//設(shè)置一組動(dòng)態(tài)圖片
_imageView.animationDuration = 3;//設(shè)置播放一組動(dòng)態(tài)圖片的事件
_imageView.animationRepeatCount = 3;//設(shè)置重復(fù)次數(shù)
[_imageView startAnimating];//開始動(dòng)畫
// [_imageView stopAnimating];//結(jié)束動(dòng)畫