IOS学习之基础UI界面总结3

//实际模式  
1:单例  类似c全局变量   2:代理(delegate)委托   3:通知中心 


: 继承  <> 代理 () 分类 


static MyClass my;
+(id)sharedMyClass
{
  @synchronized(self)  //加锁 防止多线程
  {
     if(my==nil)
     {
      my=[[[self class] alloc]init]; //放入全局变量
      }
   }
   return my;
}
//实现  两个对象去共享一个数据


MyClass *t1=[MyClass sharedMyClass];
MyClass *t2=[MyClass sharedMyClass];
t1=t2
//补充 当两个线程同时进来的时候


需要加锁


通过 xib方式来创建视图对象


NSArray *view=[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:nil];
[self.window addSubview:[view lastObject]];


手写


UILabel *label=[UILabel alloc] initWithFrame:CGRectMake(0,0,320,40)];
label.text=@"hello world";
[self.window addSubview:label];


 UIButton *Btn = [[UIButton buttonWithType:UIButtonTypeCustom]


通过tag去查找view


UIView myView=[self.view viewWithTag:100];


视图控制器//


//代码创建
UIViewController  创建基于的子类;


RootViewController *rootViewController=[[RootViewController alloc] init];
rootViewController.view.backgroundColor=[UIColor redColor];
self.window.rootViewController=rootViewController;


//nib创建  要先关联 first ----xib改rootcontroller---  view连线


RootViewController *rootViewController=[[RootViewController alloc] initWithNibName:@"View" bundle:nil];
rootViewController.view.backgroundColor=[UIColor redColor];

self.window.rootViewController=rootViewController;





/初始化root视图
MyViewController *viw=[[MyViewController alloc]init];
self.window.rootViewController=viw;
模态视图


ModelViewContraller *myview=[[ModelViewContraller alloc]init];
myview.modalTransitionStyle=UIModalTransitonStyleCrossDissolve;
[self presentViewController:myview animated:YES completion:^
{
   NSLog(@"call back");
}];


关闭模态对话框 
self dismissViewControllerAnimated 


也同可以用这个跳转回去


/UINavigationBar   初始化root


rootViewCOntraller *root=[[rootViewCOntraller alloc]init];
UINavigationContraller *nav=[[UINavigationContraller alloc]ntiWithRootViewCOntroller:root];
self.window.rootViewController=nav;




root .m 初始化  UIBarButtonItem 


UIBarButtonItem *leftbar=[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(myname)];


self.navigationItem.LeftBarButtonItem=leftbar;//左边的按钮




//右边的自定义按钮
item 是view ;
UIBarButtonItem *right=[UIBarBUttonItem alloc]initWithCustomView:item];
self.navigationItem.rightBarButtonItem=right;


//重写系统的back按钮
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] init];  


barButtonItem.title = @"buttonName";  


self.navigationItem.backBarButtonItem = barButtonItem;


[barButtonItem release];  


/loadview//setToolbarItems


UIBarButtonItem *bar1=[UIBarButtonItem alloc]initWithBarButtonSystem:UiBarBUttonSystemItemStop target:self action:nil;


UIBarButtonItem *space=[UIBarButtonItem alloc]initWithBarButtonSystem: UIBarButtonSystemItemFLexibleSpace target:self action:@selector(myname)];//空格


///自定义宽度
UIBarButtonItem *space=[UIBarButtonItem alloc]initWithBarButtonSystem: UIBarButtonSystemItemFixedSpace target:self action:@selector(myname)];
space.width=30;
//


UIBarButtonItem *bar2=[UIBarButtonItem alloc]initWithBarButtonSystem:UiBarBUttonSystemItemStop target:self action:@selector(myname)];




NSArray *arr=@[bar1,space,bar2];//底部工具栏的创建
[self.navigationController setToolbarHidden:NO aimated:YES];
[self setToolbarItems:arr animated:YES];
//工具条的创建的两种方法


1: UIToolBar *bar=[UIToolBar alloc]initWithFrame:CGRectMake(0,440,320,44)];
   bar.barstyle=UIBarStyleDefault;
  [self.view addSubview:bar];


2: [self.NavigationController settoolbarHidden:NO animated:YES];
   NSArray arr=@[v1,v2,v3];
   [self settoolbarItems:arr animated:YES];




/push下一个界面...


TwoController *two=[[TwoController alloc]init];
[self.navigationController pushViewController:two anmated:YES];




///调到顶部
[self.navigationController popToRootViewControllerAnimated:YES];


pop回一个界面


[self.navigationController popViewControllerAnimated:YES];


指定index跳转


UIViewCOntroller *secondVC=[[self.navigationCOntroller vewCOntrollers]objectAtIndex:1]
[self.navigationController popToViewController:secoundVC animated:YES];






///UITabControllor ....


UIViewController *v1=[UIViewController alloc]init];
v1.title=@"home";
v1.backgroundcolor=[UIColor redClolor];


UIViewController *v2=[UIViewController alloc]init];
v2.title=@"home";
v2.backgroundcolor=[UIColor redClolor];


UIViewController *v3=[UIViewController alloc]init];
v3.title=@"home";
v3.backgroundcolor=[UIColor redClolor];


NSArray *arr@[v1,v2,v3];
UITabBarController *bar=[[UITabBarController alloc]init];
bar.viewControllers=arr;//用数组添加进去
self.window.rootViewController=bar;


//添加图片的按钮
UITabBarItem *tab1=[[UITabBarItem alloc]initWithTabSystemItem:UITabsystemItemdownloads tag:1];
v1.tabBarItem=tab1;

v1.tabbarItem.image=;

添加徽标 v1.tabbarItem.badgetValue=@"123";


//自定义图片用initWithTitle:@"serach" image[UIImage imageNamed:@"alarm" tag:1];


//UINavigationBar   UITabControllor 的结合应用/
HomeViewController *vc1=[[HomeViewController alloc]init];
UINavigationContraller *nav=[[UINavigationContraller alloc]ntiWithRootViewCOntroller:vc1];
UITabBarItem *hometab=[[UITabBarItem alloc]initWithTabSystemItem:UITabsystemItemdownloads tag:1];
vc1.tabBarItem=hometab;
NSArray *arr@[nav,v2,v3];
UITabBarController *bar=[[UITabBarController alloc]init];
bar.viewControllers=arr;//用数组添加进去
self.window.rootViewController=bar;


///自定义tabbar
先隐藏 self.tabBar.hidden=YES;


loadCustomTabBarView  
{
  UIImageView *tabbarBG=[[UIImageView alloc]initWithFrame:CGRectMake(0,431,320,49)];
tabBarBg.image=[UIImage imageNamed:@"tabBar"];
tabBarBg.userInteractionEnabled=YES;//可以点
[self.view addSubView:tabBarBg];
  float coordx=0;
  for(int index=0;index<5;index++)
  {
    UIButton *button=[UIButton buttonWithType:UIButtoTypeRoundedRect];
    button.frame=CGRectMake(5+coordx,49.0/2-20,42,40);
    NSString *imageName=[NSString stringwithFormat:@"%d",index+1];
    [button setBackgrounImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(changeView:) forCOntrolevents: UIcontrolEventTouchUpInside];


    [tabBarBG addSubview:button];
    coordx+=62;
   }
}
-(void)changeView(UIButton*)button
{
 self.selectedIndex=button.tag;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值