ios导航条的设置(UINavigati…

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

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOp<wbr>tions:(<span style="color: #703daa">NSDictionary</span> *)launchOptions</wbr>

{

<wbr><wbr><wbr></wbr></wbr></wbr>self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

<wbr><wbr></wbr></wbr> // Override point for customization after application launch.

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

//<wbr><wbr> self.window.rootViewController = self.viewController;</wbr></wbr>



<wbr><wbr></wbr></wbr> //创建导航控制器

<wbr><wbr></wbr></wbr> UINavigationController *nvc=[[[UINavigationController alloc]initWithRootViewControll<wbr>er</wbr>:vc]autorelease];

<wbr><wbr></wbr></wbr> self.window.rootViewController=nvc;

<wbr><wbr><wbr></wbr></wbr></wbr>

<wbr><wbr><wbr></wbr></wbr></wbr>

<wbr><wbr></wbr></wbr> //修改颜色

//<wbr><wbr> nvc.navigationBar.tintColor=[UIColor blueColor];</wbr></wbr>

<wbr><wbr></wbr></wbr> //修改NAvigationBar的背景图片

<wbr><wbr></wbr></wbr> //获取背景图片

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

<wbr><wbr></wbr></wbr> UIImage *barImg=[[UIImage alloc]initWithContentsOfFile:str];

<wbr><wbr></wbr></wbr> //设置背景图片

<wbr><wbr> [nvc.</wbr></wbr>navigationBar setBackgroundImage:barImg forBarMetrics:UIBarMetricsDefault];

<wbr><wbr><wbr></wbr></wbr></wbr>


<wbr><wbr> [</wbr></wbr>self.window makeKeyAndVisible];

<wbr><wbr></wbr></wbr> return YES;

}









2)导航条添加一个UITextField

<wbr></wbr>

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

<wbr><wbr></wbr></wbr> if (self.navigationController)

<wbr><wbr> {</wbr></wbr>

<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> //创建一个UITextField

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

<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> //txt改为圆角

<wbr><wbr><wbr><wbr> txtURL.</wbr></wbr></wbr></wbr>borderStyle=UITextBorderStyleRounded<wbr>Rect<span style="color: #000000">;</span></wbr>

<wbr><wbr><wbr><wbr><span style="color: #008400">//</span><span style="line-height: normal; font-family: 'Heiti sC Light'; color: rgb(0, 132, 0);">设置字体大小</span></wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr> txtURL.<span style="color: #703daa">font</span>=[<span style="color: #703daa">UIFont</span> <span style="color: #3d1d81">systemFontOfSize</span>:<span style="color: #272ad8">12</span>];</wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr><span style="color: #008400">//</span><span style="line-height: normal; font-family: 'Heiti sC Light'; color: rgb(0, 132, 0);">设置提示</span></wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr> txtURL.<span style="color: #703daa">placeholder</span>=<span style="color: #d12f1b">@"</span><span style="line-height: normal; font-family: 'Heiti sC Light'; color: rgb(209, 47, 27);">请输入网址</span><span style="color: #d12f1b">"</span>;</wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> //设置键盘的return类型为GO

<wbr><wbr><wbr><wbr> txtURL.<span style="color: #703daa">returnKeyType</span>=<span style="color: #3d1d81">UIReturnKeyGo</span>;</wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr><span style="color: #008400">//</span><span style="line-height: normal; font-family: 'Heiti sC Light'; color: rgb(0, 132, 0);">设置代理</span></wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr> txtURL.<span style="color: #703daa">delegate</span>=<span style="color: #bb2ca2">self</span>;</wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr><span style="color: #bb2ca2">self</span>.<span style="color: #4f8187">txtURL</span>=txtURL;</wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> //创建UIBarButtonItem,添加self.txtURL

<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> UIBarButtonItem *txtURLBtn=[[[UIBarButtonItem alloc]initWithCustomView:self.txtURL]autorelease];

<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> //设置导航条的左侧按钮

<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> self.navigationItem.leftBarButtonItem=txtURLBtn;

<wbr><wbr> }</wbr></wbr>








3)导航条添加一个UIButton

<wbr></wbr>

<wbr><wbr><wbr><wbr><wbr><span style="color: #008400">//</span><span style="line-height: normal; font-family: 'Heiti sC Light'; color: rgb(0, 132, 0);">创建一个按钮</span></wbr></wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> UIButton *cancelBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];

<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> //设置按钮的位置

<wbr><wbr><wbr><wbr> cancelBtn.<span style="color: #703daa">frame</span>=<span style="color: #3d1d81">CGRectMake</span>(<span style="color: #272ad8">200</span>, <span style="color: #272ad8">5</span>, <span style="color: #272ad8">80</span>, <span style="color: #272ad8">25</span>);</wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> //设置按钮的title

<wbr><wbr><wbr><wbr> [cancelBtn</wbr></wbr></wbr></wbr> setTitle:@"取消" forState:UIControlStateNormal];

<wbr><wbr><wbr><wbr><span style="color: #703daa">UIBarButtonItem</span> *rightBtn=[[[<span style="color: #703daa">UIBarButtonItem</span> <span style="color: #3d1d81">alloc</span>]<span style="color: #3d1d81">initWithCustomView</span>:cancelBtn]<span style="color: #3d1d81">autorelease</span>];</wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> self.navigationItem.rightBarButtonItem=rightBtn;


设置完成后:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值