我想将UINavigationBar中的后退按钮设置为此图像:

我不希望图像嵌入标准后退按钮图像,我只想要显示此图像.
通过查看我可以使用的其他问题,我知道:
Run Code Online (Sandbox Code Playgroud)[[UIBarButtonItem appearance] setBackButtonBackgroundImage:barButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
设置后退按钮的背景图像.但这导致图像被拉伸,据我所知,这个特定的图像不适合被拉伸.
有没有办法可以用我的图像替换后退按钮图像?
我支持iOS 5.0及更高版本.
我怎么能在swift中得到rightbarbuttonItem的框架?我发现了这个:UIBarButtonItem:我怎样才能找到它的框架?但它说无法将NSString转换为UIView,或者无法将NSString转换为String:
let str : NSString = "view" //or type String
let theView : UIView = self.navigationItem.rightBarButtonItem!.valueForKey("view")//or 'str'
Run Code Online (Sandbox Code Playgroud)
目标是删除rightBarButtonItem,改为添加imageView,并使用fadeOut效果移动它.
谢谢
它适用于
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIColor.redColor().as1ptImage()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension UIColor {
func as1ptImage() -> UIImage {
UIGraphicsBeginImageContext(CGSizeMake(1, 1))
let ctx = UIGraphicsGetCurrentContext()
self.setFill()
CGContextFillRect(ctx, CGRect(x: 0, y: 0, width: 1, height: 1))
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
} …Run Code Online (Sandbox Code Playgroud) 我是iOS App Development的新手.
在我的应用程序中,我尝试使用导航栏后退按钮从第二个视图导航到第一个视图,但是在视图中拖放导航栏我只能获得带标题的栏.
我真的很担心,我不确定我做错了什么?我正在使用Xcode 4.3.和故事板来设计视图.
我现在得到了什么

寻找

谢谢你的帮助
我创建了一个UISegmentedControl并成功将其附加到我的navigationItem.tableView.
但是当我尝试将它附加到UIToolbar时,它会爆炸.
我确定我之前在工具栏上看过UISegementedControls - 但似乎无法让它工作.思考?
// works
NSArray *statusItems = [[NSArray alloc] initWithObjects:@"one", @"two", nil];
statusSegments_ = [[UISegmentedControl alloc] initWithItems:statusItems];
self.navigationItem.titleView = statusSegments_;
// doesn't work
NSArray *statusItems = [[NSArray alloc] initWithObjects:@"one", @"two", nil];
statusSegments_ = [[UISegmentedControl alloc] initWithItems:statusItems];
NSArray *toolbarItems = [[NSArray alloc] initWithObjects:statusSegments_, nil];
self.toolbarItems = toolbarItems;
[toolbarItems release];
Run Code Online (Sandbox Code Playgroud)
[Session started at 2010-01-01 13:40:35 -0600.] 2010-01-01 13:40:35.182 TimeSheet[15382:20b] *** -[UISegmentedControl view]: unrecognized selector sent to instance 0x3f5c3e0 2010-01-01 13:40:35.183 TimeSheet[15382:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', …
我正在使用UINavigationItem的titleView属性来设置我想要的字体大小/颜色的自定义UILabel.这是我的代码:
self.headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 400.0, 44.0)];
self.headerLabel.textAlignment = UITextAlignmentCenter;
self.headerLabel.backgroundColor = [UIColor clearColor];
self.headerLabel.font = [UIFont boldSystemFontOfSize:20.0];
self.headerLabel.textColor = [UIColor colorWithRed:0.259 green:0.280 blue:0.312 alpha:1.0];
self.navigationItem.titleView = self.headerLabel;
Run Code Online (Sandbox Code Playgroud)
在导航栏中,我还有一个左栏按钮.结果是这样的:
alt text http://cl.ly/41164eec656c96e7c913/content
如您所见,文本未正确居中.我已经尝试设置标签的x原点,但这没有效果.
我正在开发一个应用程序,我的初始视图控制器嵌入在导航控制器和标签栏控制器中.
在我的应用程序中,我有3个不同的选项卡,一个选项卡是设置视图.这是一个带5个按钮的tableview.每个按钮在触摸时都会显示相同的视图控制器.
当我触摸其中一个按钮时,我仍然有一个漂亮的绿色导航栏,但我的按钮不起作用.
我尝试将导航项拖到我的故事板中的视图中,然后在其中放置一个条形按钮项.我可以在我的故事板中看到该按钮,但是当我运行它时它不会显示在我的应用程序中.
我还在viewDidLoad()中添加了以下代码:
let leftItem = UIBarButtonItem(title: "< Back", style: .Done, target: self, action: Selector("Save"))
let rightItem = UIBarButtonItem(title: "Save", style: .Plain, target: self, action: Selector("Save"))
//self.parentViewController?.navigationItem.leftBarButtonItem = leftItem // also doesn't work
navigationController?.navigationItem.leftBarButtonItem = leftItem
navigationController?.navigationItem.rightBarButtonItem = rightItem
Run Code Online (Sandbox Code Playgroud)
但它不会有任何影响.
我检查了故事板中是否为我的视图分配了正确的UIViewController,做了几个Clean构建(CMD + Shift + K)和Rebuilds(CMD + B).
以下图片是我的故事板的一部分的屏幕截图,以及我的应用程序的屏幕截图,其中按钮不会显示.
编辑
添加了有关视图中控件的新屏幕截图.这些不工作,或没有在我viewDidLoad中额外的代码.
我有一个UINavigationController,在堆栈上包含3个UIViewControllers.
View A - is the root
View B - is pushed by View A and has `self.navigationItem.hidesBackButton = YES;`
View C - is pushed by View B and has `self.navigationItem.hidesBackButton = NO;`
Run Code Online (Sandbox Code Playgroud)
即使我将hidesBackButton设置为NO,View C也不会显示后退按钮.我该如何解决这个问题?
iphone cocoa-touch objective-c uinavigationcontroller uinavigationitem
我在显示导航栏的rightBarButtonItem时遇到问题 - 我试图在Application Delegate中以编程方式创建它,我的UINavigationController已经设置好了.
代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
RSCListViewController *list = [[RSCListViewController alloc] initWithStyle:UITableViewStylePlain];
self.navController = [[UINavigationController alloc] initWithRootViewController:list];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"+"
style:UIBarButtonItemStylePlain
target:list
action:@selector(addPressed:)];
self.navController.navigationItem.rightBarButtonItem = barButton;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[DatabaseManager openDatabase];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
运行应用程序时,导航栏上不会显示任何按钮项.
我不确定我是否遗漏了一些明显的东西 - 我尝试使用相关的Stack Overflow线程纠正问题并没有取得任何成功.
任何帮助赞赏.
objective-c uinavigationcontroller uibarbuttonitem rightbarbuttonitem uinavigationitem
我想在导航栏中显示标题的位置添加两个标签,但我很难这样做.如果我能用故事板实现这一点,那将是非常好的,但我可以看到我做不到.
正如我所见,我需要使用navigationItem,但我不知道如何做到这一点.如果有人有任何例子,或者如果有人能更具体地解释我怎么做,那将是美好的.
我需要提一下,我对Obj-C完全不熟悉,所以任何帮助都需要在Swift中.
uinavigationitem ×10
ios ×6
swift ×4
iphone ×3
objective-c ×3
cocoa-touch ×2
ipad ×1
uiappearance ×1
uilabel ×1
uitoolbar ×1
xcode4 ×1
xcode4.3 ×1