不要急,不要怕

UI常见问题

//获取屏幕大小[UIScreen mainScreen].bounds
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
//现在xcode7在进入应用时需要一个root界面需要一个UIViewController(视图控制器)
UIViewController *vc = [[UIViewController alloc]init];
//给窗口设置默认进入界面vc
self.window.rootViewController = vc;
//设置窗口颜色;
self.window.backgroundColor = [UIColor blueColor];

//控件;
//初始化;
UIView *view = [[UIView alloc]init];
//设置位置和大小
view.frame = CGRectMake(30, 60, 100, 100);
//圆形View
faceButton.layer.masksToBounds = YES;
faceButton.layer.cornerRadius = 80 / 2.0f;

//设置视图颜色;
view.backgroundColor = [UIColor redColor];
//添加到屏幕上;
[self.window addSubview:view];

UIView 控件
view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
view1.backgroundColor = [UIColor redColor];
[self.view addSubview:view1];
//得到手机屏幕的放大倍数
NSLog(@”%f”,[UIScreen mainScreen].scale);
//得到屏幕的宽度;
float myScreen = [UIScreen mainScreen].bounds.size.width;
float space = (myScreen - 200)/5;
for (int i =0; i<4; i++) {
UIView view = [[UIView alloc]init];
view.frame = CGRectMake(space+i
space+i*50, 50, 50, 50);
view.backgroundColor = [UIColor blackColor];
[self.view addSubview:view];
}

[self moveView:view1];
定时器;
[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(moveTimer:) userInfo:nil repeats:YES];
-(void)moveTimer:(id)info{

if (view1.frame.origin.x==0&&view1.frame.origin.y==0) {
view1.frame = CGRectMake(380, 0, 50, 50);
}else if (view1.frame.origin.x==380&&view1.frame.origin.y==0){
view1.frame = CGRectMake(0, 0, 50, 50);
}
}
//系统提供的位移动画;
[UIView animateWithDuration:1.0f animations:^{

if (view.frame.origin.x==0&&view.frame.origin.y==0) {
view.frame = CGRectMake(380, 0, 50, 50);
}else if (view.frame.origin.x==380&&view.frame.origin.y==0){
view.frame = CGRectMake(0, 0, 50, 50);
}

}completion:^(BOOL finished) {
[self moveView:view];
}];

#pragma mark -UIlable
UILabel lable = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, self.view.frame.size.width-10, 50)];
lable.text = @”啦啦啦”;
//无限换行;
lable.numberOfLines = 0;
//lable的背景颜色;
lable.backgroundColor = [UIColor redColor];
//字体颜色;
lable.textColor = [UIColor blueColor];
//文字对齐方式;
lable.textAlignment = NSTextAlignmentLeft;
//字体大小
lable.font = [UIFont systemFontOfSize:20.0f weight:10.0f];
//字体加粗
lable.font = [UIFont boldSystemFontOfSize:28.0f];
//字体
lable.font = [UIFont fontWithName:@”Zapfino” size:21.0f];
//字体家族;
NSArray
familyArray = [UIFont familyNames];
for (NSString fs in familyArray) {
//字体家族下的小累;
NSArray
fontNameArray = [UIFont fontNamesForFamilyName:fs];
NSLog(@”%@”,fontNameArray);
}
[self.view addSubview:lable];

#pragma mark - UIImage
//添加图片方法1:从本工程目录中添加;
NSString path = [[NSBundle mainBundle]pathForResource:@”1” ofType:@”.jpg”];
UIImage
image = [[UIImage alloc]initWithContentsOfFile:path];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
imageView.image = image;
//[self.view addSubview:imageView];

UIImageView imageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
UIImage
image2 = [UIImage imageNamed:@”1.jpg”];
imageView2.image = image2;
//UIViewContentMode按原图大小显示;~从哪开始;所以top就是全图;
//UIViewContentModeTop
//UIViewContentModeBottom
//UIViewContentModeLeft
//UIViewContentModeRight
//UIViewContentModeCenter

//UIViewContentModeScaleAspectFit更具原图的长宽比例显示,不拉扯图片
//imageView2.contentMode = UIViewContentModeCenter;
imageView2.contentMode = UIViewContentModeScaleAspectFit;

//添加边框;Width宽度;
imageView2.layer.borderWidth = 5.0f;
//边框半径
imageView2.layer.cornerRadius = 10.0f;

//边角圆化;
imageView2.layer.masksToBounds = YES;
//边角半径
imageView2.layer.cornerRadius = 50.0f;
//中心点,慎用
imageView2.center = self.view.center;
//透明度
imageView2.alpha = 0.5f;
[self.view addSubview:imageView2];

//动态图的建立;
-(void)creatGif{
//用循环的形式,将图片用数组接收
NSMutableArray marr = [[NSMutableArray alloc]init];
for (int i = 1; i<19; i++) {
UIImage
image = [UIImage imageNamed:[NSString stringWithFormat:@”DOVE %i.png”,i]];
[marr addObject:image];
}

UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 121, 96)];
//接收有图片的数组animationImages
imageView.animationImages = marr;
//接收图片的时间;
imageView.animationDuration = 2.0f;
//接收次数;0相当于无穷;
imageView.animationRepeatCount = 0;
//开始播放
[imageView startAnimating];
[self.view addSubview:imageView];

[UIView animateWithDuration:2.0f animations:^{
imageView.frame = CGRectMake(200, 500, 121, 96);
}];
}

UIButton按钮;
UIButton *but = [[UIButton alloc]initWithFrame:CGRectMake(40, 20, 300, 300)];
but.backgroundColor = [UIColor grayColor];
[but setBackgroundColor:[UIColor redColor]];
[but setTitle:@”Boom” forState:UIControlStateNormal];
[but setTitle:@”爆炸” forState:UIControlStateHighlighted];
but.titleLabel.font = [UIFont systemFontOfSize:22.0f];
//设置背景图片;背景图和image要共存的话,image要足够小不然会把背景图覆盖;
[but setBackgroundImage:[UIImage imageNamed:@”1.jpg”] forState:UIControlStateNormal];
//添加图片;
[but setImage:[UIImage imageNamed:@”1.jpg”] forState:UIControlStateNormal];
//添加tag
[but setTag:1];
but.tag = 1;
//移动坐标;
[but setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[but setImageEdgeInsets:UIEdgeInsetsMake(12, 0, 0, 0)];

[self.view addSubview:but];
[self butClink:but];
}
-(void)butClink:(UIButton )button{
UIView
v = [self.view viewWithTag:1];
//[v removeFromSuperview];
}
界面颜色;
_bgheadView.backgroundColor = [UIColor colorWithRed:36/255.0f green:173/255.0f blue:232/255.0f alpha:1];
//@”24ade8”美术什么的,ps里边的6位数字,是一种颜色(用的老师添加的一种方法)colorWithHexString
_bgheadView.backgroundColor = [UIColor colorWithHexString:@”24ade8”];
UIButton *exitbut = [UIButton buttonWithType:UIButtonTypeCustom];

//实例创造界面的一种方法;
NSArray arr =@[@”姓名”,@”性别”,@”电话”,@”编号”,@”入场时间”,@”时薪”,@”地址”,@”备注”];
NSArray
arr1 =@[@”张一鸣”,@”男”,@”18652433671”,@”NO54”,@”2013—12-02”,@”120”,@”北京市海淀区学院路”,@”语言”];
for (int j=0; j<8; j++) {
UIButton but4 =[self Name1:arr1[j] andTi:CGRectMake(screen_Width/2, 200+hang_heightj+2*j, screen_Width/2-0,hang_height) AndName2:arr[j]];

UILabel lable = [[UILabel alloc]initWithFrame:CGRectMake(30, 200+hang_heightj+2j,screen_Width/2-10 , hang_height)];
lable.text = arr[j];
lable.font = [UIFont systemFontOfSize:16.0f];
lable.textAlignment = NSTextAlignmentLeft;
lable.textColor = [UIColor colorWithHexString:@”24ade8”];
[but4 setTitleColor:[UIColor colorWithHexString:@”24ade8”] forState:UIControlStateHighlighted];
[self.view addSubview:lable];
[self.view addSubview:but4];
//封装的函数;
-(UIButton
)Name1:(NSString )name1 andTi:(CGRect)frame1 AndName2:(NSString )name2{
UIButton *exitbut = [UIButton buttonWithType:UIButtonTypeCustom];
exitbut.frame = frame1;
[exitbut setTitle:name1 forState:UIControlStateNormal];
[exitbut setTitle:name2 forState:UIControlStateHighlighted];
[exitbut setTitleColor:[ UIColor blackColor] forState:UIScrollViewDecelerationRateNormal];
return exitbut;
}

@interface ViewController() {

UITextField *textf;
}

@end

UITextField文本输入框;
@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];

//文本输入框;
textf = [[UITextField alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, 40)];
//背景色;
textf.backgroundColor = [UIColor yellowColor];
//给文本输入框添加背景图片;
textf.background = [UIImage imageNamed:@”1.png”];
//文本输入方式;
textf.placeholder = @”请输入账号”;
//secure安全文字入口(密码),变为
textf.secureTextEntry = YES;
//删除全部文字(在有文字的情况下才出现)
textf.clearButtonMode = UITextFieldViewModeAlways;
//添加一个小图片这个函数没什么用
UIImageView
image = [[UIImageView alloc]initWithFrame:CGRectMake(1000, 1000, 33, 33)];
image.image =[UIImage imageNamed:@”2.png”];
texf.leftViewMode = UITextFieldViewModeAlways;
texf.leftView = image;

//该框的键盘类型
//UIKeyboardTypeNumberPad;数字键盘;
//UIKeyboardTypeNumbersAndPunctuation 数字和标点符号键盘
//UIKeyboardTypeEmailAddress邮箱键盘;
//UIKeyboardTypeURL网站键盘;
textf.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
//该框的回车操作;
// UIReturnKeyDefault,
// UIReturnKeyGo,
// UIReturnKeyJoin,
// UIReturnKeyNext, 下一行
// UIReturnKeySearch,输入完后进行搜索
// UIReturnKeySend,发送
// UIReturnKeyDone,确定
textf.returnKeyType = UIReturnKeyNext;
textf.delegate = self;

[self.view addSubview:textf];

UITextField *texf2 = [[UITextField alloc]initWithFrame: CGRectMake(0, CGRectGetMaxY(textf.frame)+20, self.view.frame.size.width, 44)];
texf2.placeholder = @”请在此输入密码”;
texf2.backgroundColor = [UIColor purpleColor];
texf2.keyboardType = UIKeyboardTypeAlphabet;
texf2.tag = 120;
texf2.returnKeyType = UIReturnKeyDone;
//遵循协议;
texf2.delegate = self;
[self.view addSubview:texf2];
}

#pragma mark -return键的代理
-(BOOL)textFieldShouldReturn:(UITextField )textField{
if (textField==textf) {
//如果是第一个框,就跳到第二个框;
UITextField
textf1 = (UITextField )[self.view viewWithTag:120];
//第二个框框变为第一优先级;
[textf1 becomeFirstResponder];
}else{
UIAlertView
av = [[UIAlertView alloc]initWithTitle:@”消息通知” message:@”登录失败” delegate:nil cancelButtonTitle:@”找回密码” otherButtonTitles:@”再试一次”, nil];
//这个控件不用addSubview
[av show];
}
return YES;
}

键盘升降实例;
//创建一个输入框,
textf = [[UITextField alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-44, self.view.frame.size.width, 44)];
textf.backgroundColor = [UIColor redColor];
textf.returnKeyType = UIReturnKeyNext;
textf.placeholder = @”请输入文字”;
textf.delegate = self;
//当这个键盘升起的时候我们的系统会告诉我们键盘以升起
//所以我们要检测系统的这条消息
//通知中心[NSNotificationCenter defaultCenter]
[self.view addSubview:textf];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

#pragma mark - return 的系统代理;
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
//让textf放弃第一响应;
[textField resignFirstResponder];
return YES;
}

#pragma mark -升起;
-(void)keyboardWillShow:(NSNotification *)note{
//求出键盘升起时的高度;
float keyBoardHeight = [[note.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size.height;
//求出键盘升起UIKeyboardAnimationDurationUserInfoKey的时间floatValue;
float time = [[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]floatValue];
//添加动画
[UIView animateWithDuration:time animations:^{
textf.frame = CGRectMake(0, self.view.frame.size.height-keyBoardHeight- textf.frame.size.height, textf.frame.size.width, textf.frame.size.height);
}];
}

#pragma mark -降落
-(void)keyboardWillHide:(NSNotification *)note{
textf.frame = CGRectMake(0, self.view.frame.size.height-44, self.view.frame.size.width, 44);

}

滚动视图 UI

  • (void)viewDidLoad {
    [super viewDidLoad];
    [self creatUIScrollView];
    [self creatPageControl];

}

#pragma mark -创造滚图;
-(void)creatUIScrollView{
sc = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, 200)];
sc.backgroundColor = [UIColor redColor];
sc.contentSize = CGSizeMake(sc.frame.size.width*9, sc.frame.size.height);
//开始显示第2张;
sc.contentOffset = CGPointMake(sc.frame.size.width, 0);
//封页,不存在左边半张右边半张的情况
sc.pagingEnabled = YES;
//反弹 看不到背景色 后边没有就不可以滑动;
sc.bounces = NO;
//关闭进度条;
sc.showsHorizontalScrollIndicator =NO;//水平
sc.showsVerticalScrollIndicator = NO;//垂直
//代理
sc.delegate = self;
[self.view addSubview:sc];

//图片的添加;
NSArray *arr = @[@”1.jpg”,@”2.jpg”,@”3.jpg”,@”4.jpg”,@”5.jpg”,@”6.jpg”,@”7.jpg”];
marr = [NSMutableArray arrayWithArray:arr];
[marr addObject:arr[0]];
[marr insertObject:[arr lastObject] atIndex:0];

for (int i = 0; i<9; i++) {
UIImageView image = [[UIImageView alloc]initWithFrame:CGRectMake(isc.frame.size.width, 0, sc.frame.size.width, sc.frame.size.height)];
image.image = [UIImage imageNamed:marr[i]];
[sc addSubview:image];
}
//添加定时器让sc滚起来;
[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(nextPhoto) userInfo:nil repeats:YES];

}

#pragma mark - 滚动动画;
-(void)nextPhoto{
[UIView animateWithDuration:1.0f animations:^{
//sc.contentOffset.x x轴偏移量;
sc.contentOffset = CGPointMake(sc.contentOffset.x+sc.frame.size.width, 0);
//让小标点跟着偏移量动;
_pageControl.currentPage = sc.contentOffset.x/sc.frame.size.width-1;
}completion:^(BOOL finished) {
//如果跳到最后一张,回到第二张
if (sc.contentOffset.x==(marr.count-1)*sc.frame.size.width) {
sc.contentOffset=CGPointMake(sc.frame.size.width, 0);
//小标点跟着跳;
_pageControl.currentPage = sc.contentOffset.x/sc.frame.size.width-1;
}
}];
}

#pragma mark -创造下标点;
-(void)creatPageControl{
_pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(sc.frame)-40, sc.frame.size.width, 20)];
//点的数量;
_pageControl.numberOfPages = marr.count - 2;
//当前点的颜色;currentPage当前点
_pageControl.currentPageIndicatorTintColor = [UIColor redColor];
//其他点的颜色;
_pageControl.pageIndicatorTintColor = [UIColor blackColor];
[self.view addSubview:_pageControl];
}

#pragma mark - 点随图动;
//系统协议提供的
-(void)scrollView0DidScroll:(UIScrollView *)scrollView{

NSLog(@”%f,%f”,scrollView.frame.size.width,scrollView.frame.origin.y);
}
//去掉重复的第一张和最后一张;
-(void)scrollViewDidEndDecelerating:(UIScrollView )scrollView{
//如果偏移量为9-1张,则跳到第2张;
if (sc.contentOffset.x==(marr.count -1)
sc.frame.size.width) {
NSLog(@”哈哈”);
sc.contentOffset = CGPointMake(sc.frame.size.width, 0);
}if (sc.contentOffset.x == 0) {
NSLog(@”just do”);
sc.contentOffset = CGPointMake(sc.frame.size.width*(marr.count-2), 0);

}
// _pageControl.currentPage = sc.contentOffset.x/sc.frame.size.width-1;

}

//活动指示器viewUIActivityIndicatorViewStyleWhiteLarge指示器风格
UIActivityIndicatorView*activityIndicator=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

activityIndicator.center=self.view.center;
//设置颜色
activityIndicator.color=[UIColor redColor];
//设置放大
activityIndicator.transform=CGAffineTransformMakeScale(2, 2);
//设置状态条的小菊花
//系统的单例;
[UIApplication sharedApplication].networkActivityIndicatorVisible=YES;
UIViewview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
view.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
view.center=self.view.center;
//圆角
view.layer.cornerRadius=8;
activityIndicator.center=CGPointMake(view.frame.size.width/2, view.frame.size.width/2);
activityIndicator.center =CGPointMake(view.frame.size.width/2,view.frame.size.height/2);
[view addSubview:activityIndicator];
view.tag=100;
[self.view addSubview:view];
//以上还无法显示,需要设置开始
//动画开始
[activityIndicator startAnimating];
//2秒以后调取
[self performSelector:@selector(test) withObject:nil afterDelay:4];
}
-(void)test{
//停止网络请求,删除指示器
UIView
view=[self.view viewWithTag:100];
[view removeFromSuperview];
[UIApplication sharedApplication].networkActivityIndicatorVisible=NO;
}

//进度条;
UIProgressView pro = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
pro.tag = 100;
pro.frame = CGRectMake(0, 200, 400, 100);
//当前进度;
pro.progress = 0;
//完成的颜色;
pro.progressTintColor = [UIColor redColor];
//未完成的颜色;
pro.trackTintColor = [UIColor blackColor];
//以下为设置图片的方法,在iOS7.1以下无效,
UIImage
image = [UIImage imageNamed:@”1.png”];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
pro.progressImage = image;
pro.trackImage = image;

[self.view addSubview:pro];
//开始计时
[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timeClick:) userInfo:nil repeats:YES];

}
-(void)timeClick:(NSTimer )time{
UIProgressView
pro = (UIProgressView *)[self.view viewWithTag:100];
pro.progress = pro.progress + 0.1;
}

//分段控制;UISegmentedControl
NSArray array = @[@”孙悟空”,@”猪八戒”,@”唐僧”,@”白龙马”];
UISegmentedControl
seg = [[UISegmentedControl alloc]initWithItems:array];
//设置坐标;
seg.frame = CGRectMake(0, 200, 320, 100);
//给其中一个按钮设置图片 这样设置图片为阴影,如果显示图片需要一下处理
UIImage *image = [UIImage imageNamed:@”bird1.png”];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[seg setImage:image forSegmentAtIndex:1];
//添加事件;
[seg addTarget:self action:@selector(segClick:) forControlEvents:UIControlEventValueChanged];
//设置背景色;
[seg setBackgroundImage:[[UIImage alloc]init] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

//设置每个item中间的分割线;
[seg setDividerImage:[[UIImage alloc]init] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
//旋转;
seg.transform = CGAffineTransformMakeRotation(M_PI_2);
for (UIView xc in seg.subviews ) {
xc.transform = CGAffineTransformMakeRotation(M_PI_2
3);
[self.view addSubview:seg];
}
}
-(void)segClick:(UISegmentedControl )seg{
NSLog(@”哈哈”);
if (seg.numberOfSegments<6) {
[seg insertSegmentWithTitle:@”西游记” atIndex:2 animated:YES];
}
}
//滑块;
UISlider
slider = [[UISlider alloc]initWithFrame:CGRectMake(0, 100, 414, 100)];
slider.thumbTintColor = [UIColor purpleColor];
//设置滑块的图片;
[slider setThumbImage:[UIImage imageNamed:@”bird1”] forState:UIControlStateNormal];
[slider setThumbImage:[UIImage imageNamed:@”pig_2”] forState:UIControlStateHighlighted];
//设置最大值和最小值的图片;
[slider setMaximumValueImage:[UIImage imageNamed:@”bird1”]];
[slider setMinimumValueImage:[UIImage imageNamed:@”bird1”]];
//设置最大值和最小值的范围;
slider.minimumValue = 100;
slider.maximumValue = 1000;
//放手时显示数值;
slider.continuous = YES;
//设置初始停在哪里
slider.value = 500;
//最大值和最小值的颜色;
slider.minimumTrackTintColor =[UIColor yellowColor];
slider.maximumTrackTintColor = [UIColor purpleColor];

//添加事件;
[slider addTarget:self action:@selector(slickClick:) forControlEvents:UIControlEventValueChanged];

[self.view addSubview:slider];
}
-(void)slickClick:(UISlider )slider{
NSLog(@”%f”,slider.value);
}

UIStepper
stepper=[[UIStepper alloc]initWithFrame:CGRectMake(0, 100, 60, 40)];
//设置最小值
stepper.minimumValue=100;
//设置最大值
stepper.maximumValue=10000;
//设置每次点击+号跳多少
stepper.stepValue=100;
[stepper addTarget:self action:@selector(stepperClick:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:stepper];
}
-(void)stepperClick:(UIStepper*)stepper{
NSLog(@”%f”,stepper.value);
}

UItextView
UITextView*textView=[[UITextView alloc]initWithFrame:CGRectMake(0, 0, 320, 320)];
textView.backgroundColor=[UIColor blackColor];
textView.textColor=[UIColor whiteColor];
//设置字体大小
textView.font=[UIFont systemFontOfSize:25];
//设置返回按键
textView.returnKeyType=UIReturnKeySend;
//设置键盘类型
textView.keyboardType=UIKeyboardTypeEmailAddress;

//设置不可编辑
textView.editable=NO;
//设置一些文字
textView.text=@”boom shaka lakaboom shaka lakaboom shaka lakaboom”;
textView.delegate=self;
[self.view addSubview:textView];
}
//每次点击键盘输入的内容
-(BOOL)textView:(UITextView )textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString )text
{
return YES;
}
//开始编辑
-(void)textViewDidBeginEditing:(UITextView *)textView
{

}
//结束编辑
-(void)textViewDidEndEditing:(UITextView *)textView
{

}

//block 终极宝典
//1.block 一般用于反向传值
//第二个界面 要求 第一个界面 做点事情
/
1.block 必须定义在第二个界面
typedef void(^changeClolorBlock)(UIColor
);

@property (nonatomic,copy) changeClolorBlock changeColor;
2.掉用block
_changeColor([UIColor greenColor]);
3.实现block
vc.changeColor = ^(UIColor *color){

self.view.backgroundColor = color;

};

*
代理一般用于反向传值;
第二个界面向第一个界面穿值
1.定义协议是发生在第二个界面(协议和代理指针);
@protocol TwoVCDelegate

-(void)changeColor:(UIColor *)color;

@end

@property(nonatomic,assign)iddelegate;

导航条;

self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

ViewController *vc = [[ViewController alloc]init];

UINavigationController *nvc = [[UINavigationController alloc]initWithRootViewController:vc];
self.window.rootViewController = nvc;

[self.window makeKeyAndVisible];

//改变导航条的颜色;navigationBar才是正真的视图;
[self.navigationController.navigationBar setBarTintColor:[UIColor grayColor]];
//去掉导航条下边的阴影;最好配合(设置背景图片一起用)
//用一张重色的图片设置导航条,在用一张重色的图片设置为下边阴影的背景图片;
[self.navigationController.navigationBar setShadowImage:[UIImage imageNamed:@”2.jpg”]];
//设置标题的几种方式
self.title = @”主页”;//主要的;
self.navigationItem.title = @”完成”;
// 设置导航栏标题的颜色
[self.navigationController.navigationBar setTitleTextAttributes:@{UITextAttributeTextColor:[UIColor whiteColor]}];
//新方法;7.0出的
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIFont systemFontOfSize:33.0f]}];
//[UIDevice currentDevice].systemVersion floatValue当前系统版本//的浮点型号
if ([[UIDevice currentDevice].systemVersion floatValue]<7.0) {
[self.navigationController.navigationBar setTitleTextAttributes:@{UITextAttributeTextColor:[UIColor whiteColor]}];
}else{
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
}

//这个颜色设置没什么用;
[self.navigationController.navigationBar setBackgroundColor:[UIColor redColor]];
// 设置背景图片;
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@”2.jpg”] forBarMetrics:UIBarMetricsDefault];
//我想放一个自定义的标题;导航栏高度44
UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
lable.text = @”自定义标题”;
lable.font = [UIFont systemFontOfSize:33.0f];
lable.textColor = [UIColor blackColor];
lable.textAlignment = NSTextAlignmentCenter;
//把标题lable放到标题栏上
self.navigationItem.titleView = lable;

//给导航栏添加系统按钮
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(click)];
self.navigationItem.leftBarButtonItem = item;
[self.navigationItem.leftBarButtonItem setImage:[UIImage imageNamed:@”2.jpg”] ];
[self.navigationItem.leftBarButtonItem setTintColor:[UIColor blueColor]];

//自定义导航按钮
UIButton *but = [UIButton buttonWithType:UIButtonTypeContactAdd];
but.frame = CGRectMake(100, 10, 35, 35);
[but setBackgroundImage:[UIImage imageNamed:@”2.jpg”] forState:UIControlStateNormal];

[but addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *butItem = [[UIBarButtonItem alloc]initWithCustomView:but];
self.navigationItem.rightBarButtonItem = butItem;

-(void)click{
NewViewController *new = [[NewViewController alloc]init];
[self.navigationController pushViewController:new animated:YES];
}

-(void)touchesBegan:(NSSet )touches withEvent:(UIEvent )event{
NewViewController *new = [[NewViewController alloc]init];
[self.navigationController pushViewController:new animated:YES];

}

2.你在什么时候需要代理去干什么;
调用协议方法,调用(在第二个页面)
[_delegate changeColor:[UIColor purpleColor]];

3.使用代理(第一个界面)
vc.delegate = self;
4.实现代理方法;(第一个界面)
-(void)changeColor:(UIColor *)color{

self.view.backgroundColor = [UIColor blackColor];
}
/
/

视图控制器的生命周期;
1.loadView 加载;
2.viewDidLoad 正在加载;
3.viewWillAppear:界面将要出现;
4.viewDidAppear:
5.viewWillDisappear: 将要消失
6.viewDidDisappear:已经消失;
7.dealloc 和内存释放有关;
*/
-(void)loadView{
NSLog(@”1”);
[super loadView];
}
//view将要出现;
-(void)viewWillAppear:(BOOL)animated{
NSLog(@”2”);
[super viewWillAppear:animated];
}

  • (void)viewDidLoad {
    NSLog(@”3”);
    [super viewDidLoad];

}
-(void)viewDidAppear:(BOOL)animated{
NSLog(@”4”);
[super viewDidAppear:animated];

}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
}
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
}
-(void)dealloc{
//arc下不能调用super dealloc
//[super dealloc];

}

//标签条控制器;tabbar

appDelegate.m文件中的书写;
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];

MainTabBarController *main = [[MainTabBarController alloc] init];

self.window.rootViewController = main;

[self.window makeKeyAndVisible];

  • (void)viewDidLoad {
    [super viewDidLoad];

//创建一个消息中心
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(messageNotifi:) name:@”xxxxx” object:nil];

[self creatViewControllers];
//给tabbar上面的item加图片;
[self settabBarItemstyle];
}
//消息发送
-(void)touchesBegan:(NSSet )touches withEvent:(UIEvent )event{

[[NSNotificationCenter defaultCenter]postNotificationName:@”xxxxx” object:@”1”];

}

//消息接受

  • (void)messageNotifi:(NSNotification *)notifi{

UITabBarItem *item = self.tabBar.items[0];
item.badgeValue = [item.badgeValue intValue] + [notifi.object intValue] > 99?@”99+”:[NSString stringWithFormat:@”%zi”,[item.badgeValue intValue] + [notifi.object intValue]];

}

#pragma mark -创建视图;
-(void)creatViewControllers{
IndexViewController vc1 = [[IndexViewController alloc]init];
HouseViewController
vc2 = [[HouseViewController alloc]init];
AccountViewController vc3 = [[AccountViewController alloc]init];
AboutMeViewController
vc4 = [[AboutMeViewController alloc]init];

UINavigationController indexNvc = [[UINavigationController alloc]initWithRootViewController:vc1];
UINavigationController
houseNvc = [[UINavigationController alloc]initWithRootViewController:vc2];
UINavigationController AccountNvc = [[UINavigationController alloc]initWithRootViewController:vc3];
UINavigationController
AboutNvc = [[UINavigationController alloc]initWithRootViewController:vc4];
indexNvc.title = @”主页”;
houseNvc.title = @”楼房”;
AccountNvc.title = @”客户”;
AboutNvc.title = @”我”;

//把带有导航的视图控制器加到tabbar数组,让标签栏控制器去管理;
//NSArray<__kindof uiviewcontroller="" *=""> *viewControllers;
self.viewControllers = @[indexNvc,houseNvc,AccountNvc,AboutNvc];
}

//添加图片(正常,高亮)
-(void)settabBarItemstyle{
NSArray selectImageArr = @[@”tabbar_limitfree_press@2x”,@”tabbar_reduceprice_press.png”,@”tabbar_appfree_press@2x”,@”tabbar_account_press”];
NSArray
unselectImageArr = @[@”tabbar_limitfree@2x”,@”tabbar_appfree@2x”,@”tabbar_reduceprice”,@”tabbar_account”];
for (int i = 0; i<self.viewControllers.count; i++) {
UITabBarItem *item = self.tabBar.items[i];
if (i==2) {
item.badgeValue = @”43”;
}

//UIImageRenderingModeAlwaysOriginal渲染;
[item setFinishedSelectedImage:[[UIImage imageNamed:selectImageArr[i]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]withFinishedUnselectedImage:[[UIImage imageNamed:unselectImageArr[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
}

//给字体设置颜色;(高亮时)
[[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor greenColor]} forState:UIControlStateSelected];
//给字体设置颜色(普通时)
[[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];
//选择显示第几个
self.selectedIndex = 1;

tableView
//控制数据的一个代理;
tb.dataSource = self;
//控制样式;
tb.delegate = self;

#pragma mark - dataSource
//必须实现多少个 和放的格子;
-(NSInteger)tableView:(UITableView )tableView numberOfRowsInSection:(NSInteger)section{
return 10;
}
//返回格子的样子
-(UITableViewCell
)tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath )indexPath{

//复用机制;
// UITableViewCell cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
// cell.backgroundColor = [UIColor purpleColor];
// cell.textLabel.text = @”run”;
// cell.textLabel.alpha = 0.2;
UITableViewCell
cell = [tableView dequeueReusableCellWithIdentifier:@”xiao”];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@”xiao”];
cell.backgroundColor = [UIColor purpleColor];
NSLog(@”—-“);
}
//
cell.textLabel.text = _nameArray[indexPath.row];
return cell;
}

#pragma mark -大小
-(CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath{

return 200.0f;
}

#pragma mark -向左滑动出现的删除
-(NSString )tableView:(UITableView )tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{

return @”删除”;

}
-(void)tableView:(UITableView )tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath )indexPath{
[_picArray removeObjectAtIndex:indexPath.row];
[_tb reloadData];
}
//隐藏状态栏
[[UIApplication sharedApplication]setStatusBarHidden:YES];
//状态栏高亮
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];