Iphone 右按钮不显示
我有下面的代码来纠正这个错误Iphone 右按钮不显示,iphone,ios,ios4,Iphone,Ios,Ios4,我有下面的代码来纠正这个错误 UIButton* rightbutton = [UIButton buttonWithType:UIButtonTypeCustom]; [rightbutton setBackgroundImage:[UIImage imageNamed:@"share-icon.png"] forState:UIControlStateNormal]; [rightbutton addTarget:self action:@selector(share:) f
UIButton* rightbutton = [UIButton buttonWithType:UIButtonTypeCustom];
[rightbutton setBackgroundImage:[UIImage imageNamed:@"share-icon.png"] forState:UIControlStateNormal];
[rightbutton addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:rightbutton] autorelease];
但它没有表现出任何巴布托主义。相反,若我使用下面的代码,那个么barbutton项就会出现,但问题是我不能用barbuttonitem上的代码设置触摸事件
UIImageView *iconView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"dashboard-icon.png"]];
UIBarButtonItem *icon = [[UIBarButtonItem alloc] initWithCustomView:iconView];
self.navigationItem.leftBarButtonItem=icon;
[icon release];
[iconView release];
您是否已尝试为
右侧按钮设置适当的框架?e、 g.rightbutton.frame=(CGRect){CGPointZero,image.size}代码>
另请注意:
在iOS 4及更高版本上
不需要文件来指定
文件扩展名。在iOS 4之前,
您必须指定文件名
分机
您是否已尝试为右侧按钮设置适当的框架?e、 g.rightbutton.frame=(CGRect){CGPointZero,image.size}代码>
另请注意:
在iOS 4及更高版本上
不需要文件来指定
文件扩展名。在iOS 4之前,
您必须指定文件名
分机
我的猜测是,您将uibarbuttonim
添加到了错误的对象!
您需要将它添加到rootViewController(而不是像您可能做的那样添加到UINavigationController
)
我的猜测是,您将uibarbuttonim
添加到了错误的对象!
您需要将它添加到rootViewController(而不是像您可能做的那样添加到UINavigationController
)
如果您使用的是白色导航栏,请不要忘记在UIBarButtonItem上设置tintColor。我的按钮在那里,但不可见。如果您使用的是白色导航栏,请不要忘记在UIBarButtonItem上设置tintColor。我的按钮在那里,但看不见。使用swift 3.0 iOS 10.0
让customButton=UIBarButtonim(标题:“右”,样式:。普通,目标:自我,动作:#选择器(耶))
customButton.width=100.0
navigationItem.rightBarButtonItem=customButton
func yeah(发件人:维吾尔自治政府){
打印(“你的男/女”)
}使用swift 3.0 iOS 10.0
让customButton=UIBarButtonim(标题:“右”,样式:。普通,目标:自我,动作:#选择器(耶))
customButton.width=100.0
navigationItem.rightBarButtonItem=customButton
func yeah(发件人:维吾尔自治政府){
打印(“你的男/女”)
}当我为孩子设置rightBardButtonItems时,我遇到了这个问题
而不是最根的viewcontroller
视图控制器始终具有navigationitem,但不一定如此
意思是它有一个导航栏来显示它,当我为一个孩子设置rightBardButtonItems时,我遇到了这个问题
而不是最根的viewcontroller
视图控制器始终具有navigationitem,但不一定如此
意味着它有一个导航栏来显示它。我的答案包含示例代码。您需要做的是声明一个image
变量并将其设置为您的image。我的答案包含示例代码。您需要做的是声明一个image
变量并将其设置为您的图像。
YourRootViewController *theRootController = [[YourRootViewController alloc] init];
UINavigationController* navContainer = [[UINavigationController alloc] initWithRootViewController:theRootController];
UIButton* rightbutton = [UIButton buttonWithType:UIButtonTypeCustom];
[rightbutton setBackgroundImage:[UIImage imageNamed:@"share-icon.png"] forState:UIControlStateNormal];
[rightbutton addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
theRootController.navigationItem.rightBarButtonItem = rightbutton;
[navContainer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:navContainer animated:YES];