在iPhone OS 3.0中,您可以使用该setToolbarItems:animated:方法设置UINavigationController的工具栏项.但是,这需要您传入一个UIToolbarItem数组.虽然我可以以编程方式创建这些工具栏项,但我宁愿在Interface Builder中创建它们.
考虑到这一点,我在"MyGreatViewController.xib"中创建了一个UIToolbar,并用想要的工具栏项填充它.然后,在"MyGreatViewController.m"中,我从工具栏中获取项目并将它们传递给setToolbarItems:animated::
- (void)viewDidLoad {
[super viewDidLoad];
[self setToolbarItems: [toolbar items]];
}
Run Code Online (Sandbox Code Playgroud)
...在哪里toolbar是一个引用UIToolbar的IBOutlet.
这是一个好方法吗?有没有更好的方法来实现这一目标?我应该以编程方式创建项目吗?
cocoa-touch interface-builder uitoolbar uinavigationcontroller uitoolbaritem
我在我的应用程序中使用UINavigationController及其栏.现在我想更改leftBarButtonItem和rightBarButtonItem位置.我希望它们位于不同的x和y位置,具有自定义的高度和高度.
但问题是,更改框架不会改变barButtonItem的任何内容.我现在不知道为什么,但框架总是被重置为其原始坐标.
这是我在viewWillAppear中调用的代码:
UINavigationItem *navItem = [[self.navigationBar items] lastObject];
UIView *rightview = [[UIView alloc] initWithFrame:CGRectMake(0,0,66,30)];
rightview.backgroundColor = [UIColor blueColor];
//add custom view
UIBarButtonItem *search = [[UIBarButtonItem alloc] initWithCustomView:rightview];
navItem.leftBarButtonItem = search;
Run Code Online (Sandbox Code Playgroud)

视图不是从0/0开始,例如x位置是5px而不是0.
有关如何解决此问题的任何建议?
这是一个工具栏项目.
以下代码在iOS 6模拟器和iOS 6设备上运行良好.
在iOS 5模拟器和iOS 5设备中忽略阴影偏移(UITextAttributeTextShadowOffset).
[_doneButton setBackgroundImage:[UIImage imageNamed:@"standardButtonImage.png"]
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
NSDictionary *textDic = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Helvetica-Bold" size:15.0], UITextAttributeFont,
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor blackColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(1.0,1.0)], UITextAttributeTextShadowOffset, //won't honor the offset in ios5
// it's not the font, font size, text color, background image, or order in the dictionary. Must be an Apple bug.
// also doesn't work if you specify [UIBarButtonItem appearance]
nil];
[_doneButton setTitleTextAttributes:textDic forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
有没有人有相同的经验,或者任何人都可以看到这个代码有什么问题?
我想以编程方式将按钮而不是条形按钮项添加到工具栏中.我选择它是因为按钮有图像infodark defaut.
那么这是如何以编程方式完成的?
在我的应用程序中,我现在对以前使用轻型键盘的所有UITextField使用“深色”外观的键盘。
在文本字段之一的键盘上方,我创建了一个自定义UIToolbar,其中包含一些按钮,允许用户选择键盘上方的选项之一。
这似乎比实际需要的要难得多,但是我试图使UIToolBar变暗而不是变亮,无论我如何尝试,工具栏始终是白色的,我似乎只能更改按钮的颜色。工具栏,而不是工具栏本身。
工具栏是用以下代码创建的:
UIToolbar *alertToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f,
self.view.window.frame.size.width, 44.0f)];
alertToolBar.backgroundColor = [UIColor blackColor];
//alertToolBar.tintColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f];
alertToolBar.translucent = NO;
alertToolBar.items = @[ [[UIBarButtonItem alloc] initWithTitle:@" GBP"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(barButtonAddText:)],
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil],
[[UIBarButtonItem alloc] initWithTitle:@" USD"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(barButtonAddText:)],
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil],
[[UIBarButtonItem alloc] initWithTitle:@" EUR"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(barButtonAddText:)],
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil],
self.itemTextField.inputAccessoryView = alertToolBar;
Run Code Online (Sandbox Code Playgroud)
我已经使用上面(//alertToolBar.tintColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f];)注释掉的代码进行了尝试,并且条形图始终保持白色,但是只有“按钮”会改变颜色。
如何将整个工具栏更改为黑色?
任何帮助,将不胜感激!
我想在xamarin.forms中为我的移动应用程序提供一个工具栏.我浏览了网络并了解了工具栏,但我认为它适用于Windows手机而不是Android.对此问题的任何帮助都将深表感谢.Ps:我也需要选项卡页面中的工具栏.
这是我的一段代码:
//main page
namespace eSewaXamarin
{
public class App:Application
{
public App ()
{
MainPage = new TabbedPageClass ();
}
protected override void OnStart ()
{
// Handle when your app starts
}
protected override void OnSleep ()
{
// Handle when your app sleeps
}
protected override void OnResume ()
{
// Handle when your app resumes
}
}
}
//tabbed page
namespace eSewaXamarin
{
public class TabbedPageClass: TabbedPage
{
public TabbedPageClass ()
{
//this.SwipeEnabled = true;
ToolbarItems.Add(new …Run Code Online (Sandbox Code Playgroud) 你如何在 Swift 3 中创建一个 UIToolbar?我想要左边的动作和右边的动作以及中间的标题,就像大多数应用程序一样。它看起来也像一个没有后退箭头或堆栈的导航控制器。
代码是这样的:
let buttona = UIBarButtonItem(title: "Buttona", style: .plain, target: self, action: #selector(buttonaToolbar(sender:)));
let buttonb = UIBarButtonItem(title: "Buttonb", style: .plain, target: self, action: #selector(buttonbToolbar(sender:)));
let title = UILabel();
toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 44));
Run Code Online (Sandbox Code Playgroud) 我已经为Scrollview(8images)+工具栏完成了代码.当我尝试单击工具栏按钮项时,滚动视图不会按预期返回.下面是代码.
当我单击工具栏按钮,没有触发"IBAction clickprjinfo"的操作时,我已通过连接检查器中的Barbuttonitem确认已对此IBACTION执行了"SentAction".
在运行时,当我点击按住工具栏按钮+触摸scroolview屏幕+然后释放按钮,然后它触发IBACTION.
任何人都有助于通知我的错误或更好的方式来理解这一点.
-(void)viewDidLoad
{
[super viewDidLoad];
[self pgcontrolview];
}
-(void) pgcontrolview {
pageC.numberOfPages=8;
pageC.currentPage=0;
for (int i=1; i<=8; i++)
{
UIImageView *images=[[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i]]];
images.frame=CGRectMake((i-1)*1024, 0, 1024, 760);
[scroller addSubview:images];
}
scroller.delegate=self;
scroller.contentSize=CGSizeMake(1024*8, 760);
scroller.pagingEnabled=YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handle_Tap:)];
tap.numberOfTapsRequired = 1;
tap.numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:tap];
}
-(IBAction)clickprjinfo:(id)sender{
pageC.currentPage=1;
CGRect frame=scroller.frame;
frame.origin.x=0;//frame.size.width*page;
frame.origin.y=0;
[scroller scrollRectToVisible:frame animated:YES];
}
Run Code Online (Sandbox Code Playgroud)