utton 的各種方法
0.setFont 設置字體大小
1.setTitle 設置標題
2.setTitleColor 設置標題顏色
3. setTitleShadowColor 設置標題陰影顏色
4. setImage 設置圖片
5. setBackgroundImage 設置背景圖片
6. setAttributedTitle? 設置標題的 文字 顏色 陰影等
7. state 狀態
8. selected 設置點擊狀態
8. titleForState 在這個狀態下 顯示的是什么文字
9. titleColorForState? 在這個狀態下 顯示的字體顏色
10. titleShadowColorForState 在這個狀態下 顯示的字體陰影顏色
11. imageForState 在這個狀態下 顯示的圖片
12. backgroundImageForState 在這個狀態下 顯示的背景圖片
13. attributedTitleForState 這個屬性可以得到這個狀態下的文字,背景圖片 等
Button 的四種狀態
1. UIControlStateNormal? 正常狀態
2. UIControlStateHighlighted 高亮狀態
3. UIControlStateDisabled 取消禁用狀態(不顯示文字)
4. UIControlStateSelected? 點擊狀態(當點擊狀態為YES的時候 點擊的時候會不顯示文字? NO的時候一直不顯示)
1. addTarget 添加響應事件
2. UIControlEventTouchDown
設置按鈕的弧度
1. button.layer.cornerRadius=40;? ? 設置按鈕的弧度
例子:
self.view.backgroundColor = [UIColor colorWithRed:1.000 green:0.782 blue:0.972 alpha:1.000];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(100, 50, 50, 50);
button.backgroundColor = [UIColor redColor];
button.selected=YES;
[button setTitle:@"按鈕" forState:UIControlStateSelected];
[button addTarget:self action:@selector(aa:) forControlEvents:UIControlEventTouchDown];
button.layer.cornerRadius=40;
[self.view addSubview:button];
}
-(void)aa:(UIButton *)sender{
NSLog(@"ooo");
}
UITextField 文本框
1. text 文本
2. attributedText 設置文本的好多屬性(顏色? 大小)
3. textColor 文本的顏色
4. font 大小
5. textAlignment 設置文本的對齊方式
6. borderStyle? 設置文本框的風格
7. placeholder? 默認文本
8. allowsEditingTextAttributes? 允許編輯(yes允許編輯,no不可以 )
9. clearButtonMode 清除按鈕
10. leftView 左視圖
11. leftViewMode 左視圖的模式
12. rightView 右視圖
13. rightViewMode 右視圖模式
文本框 代理方法
1. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;? 開始編輯的時候調用這個方法
2. - (void)textFieldDidBeginEditing:(UITextField *)textField? 開始編輯的時候調用這個方法? 無返回值
3. - (BOOL)textFieldShouldEndEditing:(UITextField *)textField;? 結束編輯的時候調用這個方法
4. - (void)textFieldDidEndEditing:(UITextField *)textField;? 結束編輯的時候調用這個方法 無返回值
5. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;? 改變輸入的字符的時候調用
6. - (BOOL)textFieldShouldClear:(UITextField *)textField;? 點擊 清除的時候調用
7. - (BOOL)textFieldShouldReturn:(UITextField *)textField;? 點擊 return 的調用
1、輸入我想要花? 如果輸入的正確 顯示一朵花 如果不正確? 不顯示
- (void)viewDidLoad {
[super viewDidLoad];
texefield=[[UITextField alloc]initWithFrame:CGRectMake(100, 200, 200,50)];
texefield.backgroundColor=[UIColor colorWithRed:0.977 green:0.755 blue:1.000 alpha:1.000];
UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(200, 200, 200, 200)];
texefield.delegate = self;
texefield.placeholder=@"輸入";
[self.view addSubview:texefield];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[texefield resignFirstResponder];
NSString *a=texefield.text; //得到文本框輸入的文字
if ([@"hua" isEqualToString:a]) {
UIImageView *imagewview=[[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
imagewview.image=[UIImage imageNamed:@"1.jpg"];
[self.view addSubview:imagewview];
}
NSLog(@"%@",a);
return YES;
}
UILabel 的各種方法
1.text:標簽文本
2.font:標簽文本字體和字體大小
3.textAlignment:設置文本字體和字體大小
4.textColor:文本顏色
5.lineBreakMode:超出label邊界文字的截取方式
6.shadowColor:文本陰影顏色
7.shadowOffset:陰影大小
8.numberOfLines: 文本最多行數,為0時沒有最大行數限制
9.highlighted:文本高亮
10.enabled:文本是否可變
超出labe邊界文字的截取方式有6種
label1.lineBreakMode = UILineBreakModeTailTruncation;
1.UILineBreakModeWordWrap: 以空格為邊界,保留整個單詞
2. UILineBreakModeCharacterWrap:保留整個字符
3. UILineBreakModeClip: 到邊界為止
4. UILineBreakModeHeadTruncation:省略開始,以……代替
5. UILineBreakModeTailTruncation:省略結尾,以……代替
6. UILineBreakModeMiddleTruncation:省略中間,以……代替,多行時作用于最后一行
7. adjustsFontSizeToFitWidth: 文本文字自適應大小
文本對齊方式有三種:
label1.textAlignment = UITextAlignmentCenter;
1.UITextAlignmentLeft:左對齊
2.UITextAlignmenCenter:居中對齊
3.UITextAlignmen:右對齊
qq版本過低紀昭君? 20:55:19
UITabBarController? 分欄控制器
注意:(1) @property(nullable, nonatomic, assign) __kindof? @的都是屬性
- (void)都是方法
(2) UITabBarController繼承于UIViewController
1. viewControllers 存控制器的數組
2. selectedViewController 當前點擊的控制器
3. selectedIndex 點擊的是第幾個控制器
4.
5.
6.
7.
8.
9.
10.
1、創建幾個控制器繼承于UIViewController? 并在APPDelegate導入類名
2、初始化self.Window 并調用makeKeyAndVisible方法
3、準備一個存有類名的數組
4、初始化TabBarController
5、初始化一個可變數組
6、在For循環里面利用字符串轉類名方法初始化控制器
7、利用上一步初始化的控制器初始化一個導航控制器
8、把創建好的導航控制器添加進可變數組里
9、在For循環外面把可變數組賦值給分欄控制器的viewControllers數組
9、把分欄控制器賦值給self.window的根控制器
備注:如果添加圖片、或文字 在第六步利用點屬性賦值。例如: vc.tabBarItem.title = tabBarNameList[i];
vc.tabBarItem.image = [UIImage imageNamed:tabBarNameList[i]];
qq版本過低紀昭君? 20:56:44
UITabBarController? 分欄控制器
注意:(1) @property(nullable, nonatomic, assign) __kindof? @的都是屬性
- (void)都是方法
(2) UITabBarController繼承于UIViewController
1. viewControllers 存控制器的數組
2. selectedViewController 當前點擊的控制器
3. selectedIndex 點擊的是第幾個控制器
4.
5.
6.
7.
8.
9.
10.
1、創建幾個控制器繼承于UIViewController? 并在APPDelegate導入類名
2、初始化self.Window 并調用makeKeyAndVisible方法
3、準備一個存有類名的數組
4、初始化TabBarController
5、初始化一個可變數組
6、在For循環里面利用字符串轉類名方法初始化控制器
7、利用上一步初始化的控制器初始化一個導航控制器
8、把創建好的導航控制器添加進可變數組里
9、在For循環外面把可變數組賦值給分欄控制器的viewControllers數組
9、把分欄控制器賦值給self.window的根控制器
備注:如果添加圖片、或文字 在第六步利用點屬性賦值。例如: vc.tabBarItem.title = tabBarNameList[i];
vc.tabBarItem.image = [UIImage imageNamed:tabBarNameList[i]];