UITabBarController,UITextView,UIToolbar,UISearchBar的综合应用

//存放视图控制器
    NSMutableArray *_vcs=[NSMutableArray array];
    
    //第一个视图
    AViewController *a=[[AViewController alloc]init];
    //指定navigat的根视图
    UINavigationController *anavi=[[UINavigationController alloc]initWithRootViewController:a];
    //设置tabbar的信息(自定义)
    anavi.tabBarItem.title=@"A";
    anavi.tabBarItem.image=nil;

    anavi.tabBarItem.badgeValue=@"1";

//将nav控制器存放到控制器数组

    [_vcs addObject:anavi];
    [a release];
    [anavi release];

 //系统设置
   /*系统设置
    //UITabBarItem *aItem=[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:100];
    //系统设置有标题
    UITabBarItem *aItem=[[UITabBarItem alloc]initWithTitle:@"A"
                                                     image:nil
                                                       tag:1000];
    anavi.tabBarItem=aItem;
    */
    [_vcs addObject:anavi];
    BViewController *b=[[BViewController alloc]init];
    UINavigationController *bnavi=[[UINavigationController alloc]initWithRootViewController:b];
    bnavi.tabBarItem.title=@"B";
    bnavi.tabBarItem.image=nil;
    bnavi.tabBarItem.badgeValue=@"2";
    


    [_vcs addObject:bnavi];
    [b release];
    [bnavi release];
    UITabBarController *tabBarController=[[UITabBarController alloc]init];
    self.window.rootViewController=tabBarController;
    tabBarController.viewControllers=_vcs;
    tabBarController.delegate=self;
    [tabBarController release];
    return YES;
}
//将要选择

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    //TODO: panduan
    BOOL success=NO;
   //让第四个不能用
//    if ([viewController isEqual:[tabBarController.viewControllers objectAtIndex:3]]) {
//        success=NO;
//    }
    
    return success;
}
//已经选择
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    
}



#import <UIKit/UIKit.h>

@interface AViewController : UIViewController<UISearchBarDelegate>{
   
}

@end


#import "AViewController.h"

@interface AViewController ()

@end

@implementation AViewController

-(void)loadView{
    [super loadView];
    self.title=@"A";
//    UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
//    btn.frame=CGRectMake(100, 100, 100, 100);
//    [btn addTarget:self
//            action:@selector(change:)
//  forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:btn];
    UISearchBar *search=[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 320, 40)];
    [self.view addSubview:search];
    search.showsCancelButton=YES;
    search.delegate=self;
    for (UIView *v in search.subviews ) {
        if ([v  isKindOfClass:[UIButton class]]) {
            [(UIButton *)v setTitle:@"关闭"
                           forState:0];
        }
    }
    [search release];
    
}
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
    [self.view endEditing:YES];
}
-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
    [self.view endEditing:YES];
}
-(void)change:(UIButton *)sender{
    self.tabBarController.tabBar.hidden=YES;
    self.tabBarController.selectedIndex=1;
}

@end

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface BViewController : UIViewController<UITextFieldDelegate>

@end

#import "BViewController.h"

@interface BViewController ()

@end

@implementation BViewController

-(void)loadView{
    [super loadView];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    self.title=@"B";
    //文本视图
    UITextView *textView=[[UITextView alloc]initWithFrame:CGRectMake(0, 0, 320, 400)];
    textView.text=@"jiu  bu gao su ni wo shi shui ";
    textView.scrollEnabled=YES;
    textView.editable=YES;
    textView.backgroundColor=[UIColor grayColor];
    //设置边框
    textView.layer.borderColor=[UIColor blueColor].CGColor;
    //设置边框宽度
    textView.layer.borderWidth=3;
    //设置字体和大小
    textView.font=[UIFont fontWithName:@"Arial" size:14];
    textView.layer.cornerRadius=10;
    //系统字体
    [UIFont familyNames];
    [self.view addSubview:textView];
    [textView release];
    /*
    UIView *hidKeyBordView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 30)];
    hidKeyBordView.backgroundColor=[UIColor yellowColor];
    textView.inputAccessoryView=hidKeyBordView;
    [hidKeyBordView release];
    */
    NSMutableArray *array=[NSMutableArray array];
    
    //left
    UIBarButtonItem *oneItem=[[UIBarButtonItem alloc]initWithTitle:@"Done"
                                                             style:UIBarButtonItemStyleBordered
                                                            target:self
                                                            action:@selector(hideKeyBord:)];
    [array addObject:oneItem];
    [oneItem release];
    UIBarButtonItem *spaceItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:
                                //可扩展的
                                UIBarButtonSystemItemFlexibleSpace
                                                            target:nil
                                                            action:nil];
    [array addObject:spaceItem];
    [spaceItem release];

    //right
    UIBarButtonItem *twoItem=[[UIBarButtonItem alloc]initWithTitle:@"Done"
                                                             style:UIBarButtonItemStyleBordered
                                                            target:self
                                                            action:@selector(hideKeyBord:)];
    [array addObject:twoItem];
    [twoItem release];

    
    UIToolbar *toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 40)];
    toolBar.items=array;
    toolBar.barStyle=UIBarStyleDefault;
    textView.inputAccessoryView=toolBar;
}

-(void)hideKeyBord:(UIBarButtonItem *)item{
    [self.view endEditing:YES];
}
@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值