IOS Custom NavigationItem --写titleView

来源:未知 责任编辑:责任编辑 发表时间:2014-05-26 10:58 点击:
        //先自己写一个titleView
	UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 20)];//allocate titleView
	titleView.backgroundColor=[UIColor blackColor];
	//Create UILable
	UILabel	*titleText = [[UILabel alloc] initWithFrame: CGRectMake(100, 0, 50, 20)];//allocate titleText
	titleText.backgroundColor = [UIColor clearColor];
	[titleText setText:@"Title"];
	[titleView addSubview:titleText];
	[titleText release];//release titleText
	
	//Create Round UIButton
	UIButton *btnNormal = [UIButton buttonWithType:UIButtonTypeRoundedRect];
	[btnNormal setFrame:CGRectMake(0, 0, 40, 20)];
	[btnNormal addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
	[btnNormal setTitle:@"Normal" forState:UIControlStateNormal];
	[btnNormal setFont:[UIFont systemFontOfSize:8]];
	[titleView addSubview:btnNormal];
	
	
	//Set to titleView
	 self.navigationItem.titleView = titleView;
	[titleView release];//release titleView
	
	//Custom backgroundImage UIButton
	UIButton *btnCustom = [UIButton buttonWithType:UIButtonTypeRoundedRect];
	[btnCustom setFrame:CGRectMake(0, 0, 32, 32)];
	[btnCustom addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
	[btnCustom setTitle:@"CB" forState:UIControlStateNormal];
	[btnCustom setBackgroundImage:[UIImage imageNamed:@"whiteButton.png"] forState:UIControlStateNormal];
	[btnCustom setBackgroundImage:[UIImage imageNamed:@"blueButton.png"] forState:UIControlStateHighlighted];
	//Create UIBarButtonItem with the customed button
	UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:btnCustom];//allocate rightBarButton
	//Set to rightBarButtonItem
	self.navigationItem.rightBarButtonItem = rightBarButton;
	[rightBarButton release];//release rightBarButton
	

 

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • Lexical or Preprocessor Issue 'xxx.h
    • ios学习笔记(二)xcode 4.3.2下实现基本交互
    • ios版本的helloworld
    • iphone(object-c) 内存管理(3) 有效的内存管理 前半部分
    • ios学习笔记(一)xcode 4.3.2下创建第一个ios项目
    • UITableView一些方法
    • IOS类似iphone通讯录TableView的完整demo【附源码】
    • [iPhone中级]iPhone团购信息客户端的开发 (二)
    • iphone(object-c)内存管理(1)
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1