ios导航条的设置(UINavigati…

1)导航控制器的创建及导航条颜色、背景图片的设置:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

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

    // Override point for customization after application launch.

    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];

//    self.window.rootViewController = self.viewController;



    //创建导航控制器

    UINavigationController *nvc=[[[UINavigationController alloc]initWithRootViewController:vc]autorelease];

    self.window.rootViewController=nvc;

    

    

    //修改颜色

//    nvc.navigationBar.tintColor=[UIColor blueColor];

    //修改NAvigationBar的背景图片

    //获取背景图片

    NSString *str=[[NSBundle mainBundle]pathForResource:@"navigationbar_background" ofType:@"png"];

    UIImage *barImg=[[UIImage alloc]initWithContentsOfFile:str];

    //设置背景图片

    [nvc.navigationBar setBackgroundImage:barImg forBarMetrics:UIBarMetricsDefault];

    


    [self.window makeKeyAndVisible];

    return YES;

}









2)导航条添加一个UITextField

 

//如果存在导航控制器,则设置导航条

    if (self.navigationController)

    {

        //创建一个UITextField

        UITextField *txtURL=[[[UITextField alloc]initWithFrame:CGRectMake(10, 5, 200, 25)]autorelease];

        //txt改为圆角

        txtURL.borderStyle=UITextBorderStyleRoundedRect;

        //设置字体大小

        txtURL.font=[UIFont systemFontOfSize:12];

        //设置提示

        txtURL.placeholder=@"请输入网址";

        //设置键盘的return类型为GO

        txtURL.returnKeyType=UIReturnKeyGo;

        //设置代理

        txtURL.delegate=self;

        self.txtURL=txtURL;

        

        

        //创建UIBarButtonItem,添加self.txtURL

        UIBarButtonItem *txtURLBtn=[[[UIBarButtonItem alloc]initWithCustomView:self.txtURL]autorelease];

        //设置导航条的左侧按钮

        self.navigationItem.leftBarButtonItem=txtURLBtn;

    }








3)导航条添加一个UIButton

 

        //创建一个按钮

        UIButton *cancelBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];

        //设置按钮的位置

        cancelBtn.frame=CGRectMake(200, 5, 80, 25);

        //设置按钮的title

        [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];

        UIBarButtonItem *rightBtn=[[[UIBarButtonItem alloc]initWithCustomView:cancelBtn]autorelease];

        self.navigationItem.rightBarButtonItem=rightBtn;


设置完成后:

[转载]ios导航条的设置(UINavigationBar)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值