Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UINavigationBar标题内的UISegmentedControl看起来未格式化_Iphone_Uinavigationcontroller_Uinavigationbar_Uisegmentedcontrol - Fatal编程技术网

Iphone UINavigationBar标题内的UISegmentedControl看起来未格式化

Iphone UINavigationBar标题内的UISegmentedControl看起来未格式化,iphone,uinavigationcontroller,uinavigationbar,uisegmentedcontrol,Iphone,Uinavigationcontroller,Uinavigationbar,Uisegmentedcontrol,我正在尝试在UINavigationController的标题中添加UISegmentedControl。但是,格式看起来是这样的(即它很难看) 当我想让它看起来像这样(漂亮:)。有人能帮忙吗 我读过红工匠的通俗例子。但我并没有把它作为我的第一个视图来显示(就像RedArtisan一样),所以我已经从AppDelegate中删除了很多代码。在应用程序委托中,我确实将此屏幕设置为UINavigationController,其根视图为UIViewController GenInfoViewCo

我正在尝试在UINavigationController的标题中添加UISegmentedControl。但是,格式看起来是这样的(即它很难看)

当我想让它看起来像这样(漂亮:)。有人能帮忙吗

我读过红工匠的通俗例子。但我并没有把它作为我的第一个视图来显示(就像RedArtisan一样),所以我已经从AppDelegate中删除了很多代码。在应用程序委托中,我确实将此屏幕设置为UINavigationController,其根视图为UIViewController

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

UINavigationController *genInfoNavController = [[UINavigationController alloc] initWithRootViewController:genInfoController];
然后在geninfo viewcontroller.m的viewdiload中执行以下操作:

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

要设置分段控件的样式,请将
segmentedControlStyle
属性设置为以下选项之一:

self.segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"Info",@"Map"]];
self.navigationItem.titleView = self.segmentedControl;
UISegmentedControlStylePlain
UISegmentedControlStyleBordered
UISegmentedControlStyleBar
UISegmentedControlStyleBezeled
例如:

self.segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"Info",@"Map"]];
self.segmentedControl.segmentedControlStyle = UISegmentedControlStyleBordered;
self.navigationItem.titleView = self.segmentedControl;
这里有一些关于样式分段控件的相关Q+As:


如果您想尝试自定义分段控件,请查看所有可用和可用控件

是的,您需要在UI分段控件上设置属性“segmentedControlStyle”

你的选择如下:

typedef enum {
   UISegmentedControlStylePlain,
   UISegmentedControlStyleBordered,
   UISegmentedControlStyleBar, // This is probably the one you want!
   UISegmentedControlStyleBezeled,
} UISegmentedControlStyle;
因此,以下内容可能会起到作用:

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

你可能还想考虑的是设置分段控件的“TimeTo彩”。

self.segmentedControl = [UIColor blackColour];
会给你留下这样的东西:


显然,你也可以做很多其他的定制。请查看此处的文档:

segmentedControlStyle
不推荐用于iOS7+。