Ios 在Xcode5中以编程方式创建连接按钮
我试图以编程方式在Xcode 5中向我的项目添加一个connect按钮,类似于此链接中示例的concept中所示的按钮: 我使用的代码如下所示:Ios 在Xcode5中以编程方式创建连接按钮,ios,button,user-interface,xcode5,Ios,Button,User Interface,Xcode5,我试图以编程方式在Xcode 5中向我的项目添加一个connect按钮,类似于此链接中示例的concept中所示的按钮: 我使用的代码如下所示: - (void) setupConnectButton { UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:self.peripheral.isConnected ? NSLocalizedString(@"Disconnect", nil) : NSLocaliz
- (void) setupConnectButton
{
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:self.peripheral.isConnected ? NSLocalizedString(@"Disconnect", nil) : NSLocalizedString(@"Connect", nil) style:UIBarButtonItemStyleBordered target:self action:@selector(connectAction:)];
self.navigationItem.leftBarButtonItem = item;
self.navigationItem.leftBarButtonItem.enabled = (self.peripheral != nil);
self.beatsPerMinute.hidden = !self.peripheral.isConnected;
self.legendLabel.hidden = !self.peripheral.isConnected;
}
但是,当我启动应用程序时,按钮没有出现……是否可能是因为我创建的图形在视图中以某种方式阻止了按钮
编辑:我使用与苹果的AcceleratorGraph项目相同的代码创建图形:
绘制图形的代码如下所示:
// The graph view itself exists only to draw the background and gridlines. All other content is drawn either into
// the GraphTextView or into a layer managed by a GraphViewSegment.
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
// Fill in the background
CGContextSetFillColorWithColor(context, graphBackgroundColor());
CGContextFillRect(context, self.bounds);
CGFloat width = self.bounds.size.width;
CGContextTranslateCTM(context, 0.0, 56.0);
// Draw the grid lines
DrawGridlines(context, 0.0, width);
}
试试这几行代码
UIBarButtonItem *firstButton = [[UIBarButtonItem alloc] initWithTitle:@"First" style:UIBarButtonItemStyleBordered target:self action:@selector(firstButtonAction:)];
UIBarButtonItem *secondButton = [[UIBarButtonItem alloc] initWithTitle:@"Second" style:UIBarButtonItemStyleBordered target:self action:@selector(secondButtonAction:)];
UIToolbarTransparent *toolbar = [UIToolbarTransparent new];
[toolbar setFrame:CGRectMake(0,0, 140,44)];
[toolbar setItems:[NSArray arrayWithObjects:firstButton, secondButton, nil]];
UIBarButtonItem *customBarButton = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
self.navigationItem.leftBarButtonItem = customBarButton;
您正在使用导航控制器吗?你能展示一下你是如何创建“图形”的吗?嗨@sergio,我编辑了这个问题来展示图形是如何绘制的。谢谢,尼克