gpt4 book ai didi

ios - IOS导航栏项目调整

转载 作者:行者123 更新时间:2023-11-29 00:17:04 24 4
gpt4 key购买 nike

我有一个导航栏按钮。我已经使用了图像,但我面临一个问题,如果我单击按钮,它会更改其位置并从导航栏向下移动到 View Controller 的 View 中。我的代码是,

 UIBarButtonItem *rightButton = [[UIBarButtonItem alloc]
initWithTitle:@""
style:UIBarButtonItemStyleDone
target:self
action:@selector(rightBtnClicked:)];
[rightButton setImage:[UIImage imageNamed:@"right.png"]];
rightButton.tintColor=[UIColor whiteColor];

self.navigationItem.rightBarButtonItem = rightButton;

enter image description here

enter image description here

最佳答案

我刚刚检查了这是否有效

    UIButton *someButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
[someButton setImage:[UIImage imageNamed:@"IMG_1148.jpg"] forState:UIControlStateNormal];
[someButton addTarget:self action:@selector(requestButton)
forControlEvents:UIControlEventTouchUpInside];


UIBarButtonItem *barButton =[[UIBarButtonItem alloc] initWithCustomView:someButton];
self.navigationItem.rightBarButtonItem=barButton;

或者你可以这样做

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 20, 20);
UIImage *image = [[UIImage imageNamed:@"back.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[button setImage:image forState:UIControlStateNormal];
button.tintColor = [UIColor redColor];
[button addTarget:self action:@selector(requestButton)
forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *mailbutton =[[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.rightBarButtonItem=mailbutton;

关于ios - IOS导航栏项目调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45102473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com