0

我试图在UINavigationController的标题内添加一个UISegmentedControl。但是,格式看起来像这样(即丑陋)。UINavigationControl里面的UINavigationBar标题看起来没有格式化

enter image description here

当我希望它看起来像这样(漂亮:)。谁能帮忙?

enter image description here

我已经红工匠here阅读通俗的例子。但是我并没有把它看作我的第一个视图(就像Red Artisan一样),所以我将很多代码从App Delegate中移出。在应用程序委托中,我将此屏幕设置为UINavigationController,其rootView是UIViewController。

GenInfoViewController *genInfoController = [[GenInfoViewController alloc] initWithNibName:@"GenInfoViewController" bundle:nil]; 

UINavigationController *genInfoNavController = [[UINavigationController alloc] initWithRootViewController:genInfoController]; 

然后在GenInfoViewController.m的viewDidLoad中我做到以下几点:

self.segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"Info",@"Map"]]; 
self.navigationItem.titleView = self.segmentedControl; 

回答

0

款式分段控制,该segmentedControlStyle属性设置为下列之一:

UISegmentedControlStylePlain 
UISegmentedControlStyleBordered 
UISegmentedControlStyleBar 
UISegmentedControlStyleBezeled 

对于例如:

self.segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"Info",@"Map"]]; 
self.segmentedControl.segmentedControlStyle = UISegmentedControlStyleBordered; 
self.navigationItem.titleView = self.segmentedControl; 

这里也有一些相关的Q +作为在这里关于造型段控制:

如果您想尝试自定义分段控制,检查拿出所有可用的CocoaControlsCocoaPods

+0

'segmentedControlStyle'弃用iOS7 +。 – Zorayr 2015-08-04 05:27:48

0

是的,你需要在你的UISegmented控件上设置属性“segmentedControlStyle”。

您的选项如下:

typedef enum { 
    UISegmentedControlStylePlain, 
    UISegmentedControlStyleBordered, 
    UISegmentedControlStyleBar, // This is probably the one you want! 
    UISegmentedControlStyleBezeled, 
} UISegmentedControlStyle; 

所以下面可能应该做的伎俩:你可能还需要考虑的是设置“tintColor”

self.segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"Info",@"Map"]]; 
self.segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; 
self.navigationItem.titleView = self.segmentedControl; 

一件事的分割也控制。

self.segmentedControl = [UIColor blackColour]; 

你会留下这样的事情:

UISegmented Control

显然还有很多其他的定制,你可以做太多的。看看这里的文档:http://developer.apple.com/library/ios/#documentation/uikit/reference/UISegmentedControl_Class/Reference/UISegmentedControl.html

相关问题