阶段整理
#pragma mark - 1.UILabel、UIButton
//创建lable
UILabel*lable=[[UILabelalloc]init];
//设置frame
lable.frame=CGRectMake(60,20,200,50);
lable.text=@"早安泰安";
//设置文本颜色
lable.textColor=[UIColor redColor];
//设置字体
lable.font= [UIFont systemFontOfSize:50];
//设置显示文本行数
lable.numberOfLines=1;
//设置对齐方式
lable.textAlignment=NSTextAlignmentCenter;
//设置背景颜色
lable.backgroundColor=[UIColor yellowColor];
//创建button
UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
button.frame= CGRectMake(20, 60, 280, 50);
button.backgroundColor=[UIColor grayColor];
//设置按钮的内边距
button.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
//设置按钮标题的内边距
button.titleEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
//给按钮添加一个点击事件
[button addTarget:self action:@selector(chickButton:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"点我" forState:UIControlStateNormal];
//[button setBackgroundImage:nil forState:UIControlStateHighlighted];
[self.view addSubview:button];
}
//点击方法的实现
-(void)chickButton:(UIButton*)a
{
NSLog(@"点过了");
[a setTitle:@"点过了" forState:UIControlStateNormal];
a.hidden=NO;//是否隐藏
}
#pragma mark - 2.UITextField
UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(30, 40, 260, 35)];
//背景
textField.backgroundColor=[UIColor greenColor];
//文本
textField.text = @"这是一个输入框";
//提示信息(当前文本长度为0显示)
textField.placeholder=@"请输入";
//文本显示颜色以及对齐方式
textField.textColor=[UIColor redColor];
textField.textAlignment=NSTextAlignmentRight;
//显示字体
textField.font=[UIFont systemFontOfSize:20];
//文字自适应默认NO;
textField.adjustsFontSizeToFitWidth=YES;
//设置最小字体(ios6以后不能使用)
//textField.minimumFontSize=50;
//设置清除按钮
textField.clearButtonMode=UITextFieldViewModeWhileEditing;
//在下次输入的时候,清楚当前内容
textField.clearsOnBeginEditing=YES;
//加密处理
textField.secureTextEntry=NO;
//设置输入框样式
textField.borderStyle = UITextBorderStyleRoundedRect;
//交互
textField.userInteractionEnabled=NO;//
textField.enabled=NO;
//设置键盘
textField.keyboardType=UIKeyboardTypeDefault;
//设置首字母是否大写
textField.autocapitalizationType=UITextAutocapitalizationTypeNone;
//return按键样式
textField.returnKeyType = UIReturnKeyDone;
//键盘外观
textField.keyboardAppearance=UIKeyboardAppearanceDark;
#pragma mark - 3. UISegmentedControl、 UISwitch、 UISlider
1.分段控制器(并不是视图的控制器)
//NSArray *item_array=@[@"A",@"B",@"C",@"D"];
UISegmentedControl* segmentC = [[UISegmentedControl alloc]initWithItems:@[@"A",@"B",@"C",@"D"]];
NSLog(@"默认:%@",NSStringFromCGRect(segmentC.frame));
segmentC.frame=CGRectMake(20, 80, 200, 50);
//插入按钮
[segmentC insertSegmentWithTitle:@"点" atIndex:1 animated:NO];
segmentC.tintColor=[UIColor redColor];
//segmentC.numberOfSegments;获取子按钮的个数只读属性
//默认选中哪一个子按钮
segmentC.selectedSegmentIndex = 2;
//设置点击之后恢复到默认状态
segmentC.momentary=YES;
//设置指定下标的子按钮的宽度
[segmentC setWidth:30 forSegmentAtIndex:1];
//设置指定下标的子按钮不可点
[segmentC setEnabled:NO forSegmentAtIndex:1];
[segmentC addTarget:self action:@selector(doSegment:) forControlEvents:UIControlEventValueChanged];
-(void)doSegment:(UISegmentedControl*)sender
{
NSLog(@"%d",sender.selectedSegmentIndex);
if (sender.selectedSegmentIndex == 0) {
NSLog(@"点击了第一个按钮%@",[sender titleForSegmentAtIndex:0]);
}
}
2.选择开关(yes、no)
UISwitch *aSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(20, 40, 0, 0)];
NSLog( @"默认:%@",NSStringFromCGRect(aSwitch.frame));
aSwitch.on=YES;
aSwitch.onTintColor=[UIColor redColor];
aSwitch.tintColor=[UIColor grayColor];
aSwitch.thumbTintColor=[UIColor greenColor];
//给选择按钮添加事件,执行动作为控件内部的值发生了变化
[aSwitch addTarget:self action:@selector(doSwitch:) forControlEvents:UIControlEventValueChanged];
-(void)doSwitch:(UISwitch*)sender
{
if (sender.on== NO) {
NSLog(@"关闭");
}else{
NSLog(@"打开");
}
}
3.滑块开关(0~1)
UISlider*slider = [[UISlider alloc]initWithFrame:CGRectMake(90, 40, 100, 34)];
NSLog(@"默认:%@",NSStringFromCGRect(slider.frame));
//设置最大可取值
slider.maximumValue=100;
//设置最小可取值
slider.minimumValue=0;
//设置滑块按钮默认显示的位置(0~1);
slider.value=0.8;
slider.maximumTrackTintColor=[UIColorredColor];
slider.minimumTrackTintColor=[UIColorpurpleColor];
slider.thumbTintColor=[UIColororangeColor];
//给滑块开关添加事件
[slider addTarget:self action:@selector(doSlider:) forControlEvents:UIControlEventValueChanged];
-(void)doSlider:(UISlider*)slider
{
NSLog(@"%g",slider.value);
}
#pragma mark - 4. UINavigationController
//标题
self.navigationItem.title = @"第2页";
//左边按钮(创建方式一)
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithTitle:@"返回吗" style:UIBarButtonItemStylePlain target:self action:@selector(doReturn)];
self.navigationItem.leftBarButtonItem = leftItem;
//右边按钮(创建方式二)
UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
self.navigationItem.rightBarButtonItem = rightItem;
//显示副标题
self.navigationItem.prompt = @"hello";
//压栈、出栈
push<-->pop ===>self.navigationController 调用;
present<-->dismiss ===>self 调用;
~push压栈为前提下的出栈的方式:
//直接出栈,一直到栈底(仅剩一个控制器的时候)
[self.navigationController popToRootViewControllerAnimated:YES];
//指定栈内存中的某个控制器
[self.navigationController popToViewController:fiveVC animated:YES];
//一个一个的出栈
[self.navigationController popViewControllerAnimated:YES];
######pragma mark - 5.UIToolbar、UIBarButtonItem、UITextView、UISearchBar
//文本段落输入框
UITextView*_textView = [[UITextViewalloc]initWithFrame:CGRectMake(30,50,260,200)];
_textView.backgroundColor = [UIColor orangeColor];
_textView.delegate = self;
_textView.font = [UIFont systemFontOfSize:24];
_textView.text = @"hello world";//默认文本
_textView.editable = YES;//是否可编辑
_textView.scrollEnabled = YES;//是否可滚动
_textView.scrollsToTop = YES;//是否可滚动到顶部
_textView.showsHorizontalScrollIndicator = NO;//显示垂直的滚动条
[self.view addSubview:_textView];
//文本段落输入框常用方法
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
NSLog(@"开始编辑");
return YES;
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView{
NSLog(@"结束编辑");
return YES;
}
- (void)textViewDidBeginEditing:(UITextView *)textView{
NSLog(@"已经开始编辑");
}
- (void)textViewDidEndEditing:(UITextView *)textView{
NSLog(@"已经结束编辑");
}
- (void)textViewDidChange:(UITextView *)textView{
NSLog(@"改变了");
}
- (void)textViewDidChangeSelection:(UITextView *)textView{
NSLog(@"%@",textView.text);
}
//工具条
UIToolbar *_toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 568-44, 320, 44)];
_toolBar.backgroundColor = [UIColor redColor];//设置背景色(会有半透明遮盖条)
//_tooBar.barTintColor = [UIColor redColor];//工具条渲染
_toolBar.barStyle = UIBarStyleBlack;//设置工具条样式
//创建工具条的子控件
UIBarButtonItem *item1 = [[UIBarButtonItem alloc]initWithTitle:@"item" style:UIBarButtonItemStylePlain target:self action:nil];
UIBarButtonItem *item_space = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *item2 = [[UIBarButtonItem alloc]initWithTitle:@"item" style:UIBarButtonItemStylePlain target:self action:nil];
//自定义工具条上的按钮
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"drink.png"] forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, 30, 25);
UIBarButtonItem *item3 = [[UIBarButtonItem alloc]initWithCustomView:button];
//在工具条添加子控件
_toolBar.items = @[item1,item_space,item2,item_space,item3];
[self.view addSubview:_toolBar];
//搜索条
UISearchBar *_searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(30, 350, 260, 30)];
_searchBar.barTintColor = [UIColor redColor];//搜索条的渲染颜色
_searchBar.tintColor = [UIColor blueColor];//光标颜色
_searchBar.searchBarStyle = UISearchBarStyleMinimal;//搜索条样式
_searchBar.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;//设置大写风格
//_searchBar.prompt = @"搜索条";
_searchBar.showsCancelButton = YES;//展示右边小图标的样式为cancel
_searchBar.showsBookmarkButton = YES;//搜索框右边展示一本书
[self.view addSubview:_searchBar];
#pragma mark - 6.滚动视图、小白点
UIScrollView *_scrollView;//全局变量
UIImageView *_imageView;//全局变量
UIImage * img = [UIImage imageNamed:@"quan.jpg"];
_imageView = [[UIImageView alloc]initWithImage:img];
_imageView.frame = CGRectMake(0, 0, 722, 220);
//创建滚动视图
_scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(10, 180, 300, 200)];
_scrollView.backgroundColor = [UIColor orangeColor];
//可滚动范围
_scrollView.contentSize = CGSizeMake(722, 220);
//弹跳属性关闭
_scrollView.bounces = NO;
//显示水平或者垂直的进度条
_scrollView.showsHorizontalScrollIndicator = YES;
_scrollView.showsVerticalScrollIndicator = YES;
//是否可滚动
_scrollView.scrollEnabled = YES;
//交互
_scrollView.userInteractionEnabled = YES;
//设置默认位置(设置x坐标显示图片中间)
[_scrollView setContentOffset:CGPointMake(161, 0) animated:YES];
//触摸状态栏可滚动到顶部(y坐标)
_scrollView.scrollsToTop = YES;
//是否按照分页显示的效果显示
_scrollView.pagingEnabled =YES;
//放大缩小(按住alt放大缩小 要求两个圆点得在图片范围内)
_scrollView.minimumZoomScale = 0.5;
_scrollView.maximumZoomScale = 4.0;
_scrollView.delegate = self;
//放大和缩小(方法)
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return _imageView;//返回全局变量
}
[_scrollView addSubview:_imageView];
[self.view addSubview:_scrollView];
//小白点
pageC.numberOfPages = 5;
pageC.tag = 120;
pageC.pageIndicatorTintColor = [UIColor redColor]; //未选中颜色
pageC.currentPageIndicatorTintColor = [UIColor blueColor];//当前显示颜色
pageC.currentPage = 0;//默认位置
//给pageC添加事件
[pageC addTarget:self action:@selector(doPageControl:) forControlEvents:UIControlEventValueChanged];
#pragma mark - 7.表视图
//创建表视图
UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
tableView.delegate = self;
tableView.dataSource = self;
tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0);//顶部有20空余为了避免与运营商重叠
//表视图头部View
tableView.tableHeaderView = [UIButton buttonWithType:UIButtonTypeContactAdd];
//设置分隔线样式
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//设置分隔线颜色
tableView.separatorColor = [UIColor redColor];
*cell
//显示主信息
cell.textLabel.text = string;
//展示详情信息
cell.detailTextLabel.text = @"The Info";
//显示图标
cell.imageView.image = [UIImage imageNamed:@"updata.jpg"];
//设置背景视图(cell)
UIView *bgView = [[UIView alloc]init];
bgView.backgroundColor = [UIColor greenColor];
cell.backgroundView = bgView;
//指示器类型
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.accessoryView = [[UISwitch alloc]init];
//选中背景
UIView *seletedView = [[UIView alloc]init];
seletedView.backgroundColor = [UIColor redColor];
cell.selectedBackgroundView = seletedView;
//设置选中样式
cell.selectionStyle = UITableViewCellSelectionStyleNone;
#pragma mark - 8. UIApplication
UIApplication *app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
//打开用户的操作权限
float verson = [[[UIDevice currentDevice] systemVersion] floatValue];
if (verson >=8.0) {
UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:setting];
}
//设置应用程序小图标上面的数字
app.applicationIconBadgeNumber = 2;
//设置网络连接状态的进度轮(状态栏)
app.networkActivityIndicatorVisible = YES;
//[app openURL:[NSURL URLWithString:@"http:www.baidu.com"]];//加载浏览器
//[app openURL:[NSURL URLWithString:@"tel://10086"]];//打电话
//[app openURL:[NSURL URLWithString:@"sms://10086"]];//发信息
//[app openURL:[NSURL URLWithString:@"mailto://10086@qq.com"]];//发邮件