UINavigationBar和UIToolbar设置title和按钮

/*下面是UINavigationBar*/

//创建一个导航栏

UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];

//把导航栏添加到视图中

[self.view addSubview:navigationBar];

//创建一个导航栏集合

UINavigationItem *navigationItem = [[UINavigationItem alloc] init];

//创建一个左边按钮

UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"左边" style:UIBarButtonItemStyleBordered target:self action:@selector(clickLeftButton)];

//创建一个右边按钮

UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"右边" style:UIBarButtonItemStyleDone target:self action:@selector(clickRightButton)];

//把左右两个按钮添加入导航栏集合中

[navigationItem setLeftBarButtonItem:leftButton];

[navigationItem setRightBarButtonItem:rightButton];

//设置导航栏内容

[navigationItem setTitle:@"标题"];

//把导航栏集合添加入导航栏中,设置动画关闭

[navigationBar pushNavigationItem:navigationItem animated:NO];

//如果碰到是UINavigationController要添加一个按钮的话

UINavigationController *nav;

nav.rightBarButtonItem = xxx;

nav.leftBarButtonItem = xxx;

/****************************************/

/*下面是UIToolbar*/

//标题栏

UIToolbar * aToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].applicationFrame.size.height-44, 320, 44)];

aToolbar.tintColor = [UIColor blackColor];

[self.view addSubview:aToolbar];

//返回

UIBarButtonItem * backItem = [[UIBarButtonItem alloc] initWithTitle:@"返回"

style:UIBarButtonItemStyleBordered

target:self

action:@selector(backUpPage:)];

backItem.tintColor = [UIColor grayColor];

//标题

UIBarButtonItem * titleItem = [[UIBarButtonItem alloc] initWithTitle:@"选择城市"

style:UIBarButtonItemStylePlain

target:nil

action:nil];

//确定按钮

UIBarButtonItem * confirmItem = [[UIBarButtonItem alloc] initWithTitle:@"确定"

style:UIBarButtonItemStyleBordered

target:self

action:@selector(confirmSelectCity:)];

confirmItem.tintColor=[UIColor grayColor];

//站位Item

UIBarButtonItem * spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace

target:nil

action:nil];

aToolbar.items = [NSArray arrayWithObjects:backItem, spaceItem, titleItem, spaceItem,confirmItem, nil];

时间: 2024-08-25 06:40:14

UINavigationBar和UIToolbar设置title和按钮的相关文章

iOS UIButton同时设置title和image属性

在iOS开发中,使用UIButton设置title和image,达到tabBarItem的效果,即title在下,image在上: 目前,我发现有两种比较好的方法: 方法一,使用UIEdgeInsets UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; [button setFrame:CGRectMake(100, 100, 60, 60)]; [button setBackgroundColor:[UIColor

使用Autolayout来设置多个按钮相同间距

在storyboard中,想要用autolayout设置多个按钮按照相同的间距排列,且根据屏幕宽度调整间距大小,就我了解,没有直接的设置方法.只用storyboard+代码的方法实现 1,首先在storyboard中放置四个按钮,并同时选中它们 2,设置好宽,高,supview下边界的距离等约束 font3,设置完成后选中第一个按钮 4,设置它距离左边界的约束 5,设置第二个,以此类推 6,在代码中写好IBOutlte,分别是四个按钮到边的约束和其中一个按钮的宽度约束 7,选中ViewContr

UIToolbar自定义背景及按钮设置

如果toolbar直接设置frame为CGRectMake(0, 0, 320, 66)的话,左右两边的按钮会往上跑(按钮水平居中的高度是66),所以可以写下面的代码覆盖状态栏的颜色(不用考虑toolbar左右两边的按钮位置除外) //覆盖状态栏的颜色 UIView *statusView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 22)]; //创建toolbar MyToolbar *toolbar = [[MyToolbar

UIAlertController 简单修改title以及按钮的字体颜色

苦逼的开发者,最终败给了一个任性的UI,系统原生UIAlertController的按纽颜色必须改.于是,开始了不归路.之前的版本是自己用view写的一个仿系统UIActionSheet,动画感觉都挺好,就是毛玻璃背景没有系统的好,由于最低兼容了ios8,所以就抛弃了UIActionSheet,改用UIAlertController. 做法其实很简单,采用runtime机制.对于runtime不了解的,我想还是别看各种介绍文章了,找一个简单的demo多写几遍,就行了. 做法很简单,自己写一个类

Delphi自写组件:可设置颜色的按钮(改成BS_OWNERDRAW风格,然后CN_DRAWITEM)

unit ColorButton; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, StdCtrls; type TColorButton = class(TButton) private //添加Color属性,默认clWhite { Private declarations } FColor:TColor; FCanvas:TCanvas; IsFocused:Boolean; procedur

iOS- 友盟社会化分享-如何设置title

支持title设置的平台:QQ.QQ空间.微信.微信朋友圈 QQtitle设置方法: [UMSocialData defaultData].extConfig.qqData.title = @"QQtitle"; 微信title设置方法: [UMSocialData defaultData].extConfig.wechatSessionData.title = @"微信title"; 朋友圈title设置方法: [UMSocialData defaultData]

Android设置AlertDialog中按钮的可用(Enable)状态

弹出一个保存文件的对话框,要控制输入内容限制,同时内容为空时保存按钮不可用.直接上代码: LayoutInflater mInflater = LayoutInflater.from(mActivity); View saveView = mInflater.inflate(R.layout.alert_dlg_save, null); // 设置输入文件名的EditText属性 final EditText filename = (EditText) saveView.findViewById

vue 路由meta 设置title 导航隐藏

router.js routes: [{ path: '/', name: 'HelloWorld', component: HelloWorld, meta: { title: "HelloWorld", 要现实的title show: true 设置导航隐藏显示 } }] App.vue <template> <div id="app"> <router-view></router-view> <bottom

微信分享自定义设置Title与Desc

前端Js引用: 1 <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> 2 <script> 3 function wxconfig(data) { 4 wx.config({ 5 // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印. 6 debug: fals