0

我在名为 login 的项目中有标签栏按钮 我想为此分配自定义图像 知道怎么可能吗?

我正在按照以下方式进行操作,但应用程序崩溃了。

这是代码:

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Login" style:UIBarButtonItemStyleBordered target:self action:@selector(loginPressed)];
self.navigationItem.leftBarButtonItem = nil;
[self.navigationItem.rightBarButtonItem setBackgroundImage:[UIImage imageNamed:@"loginN.png"] f
4

2 回答 2

1

以这种方式尝试:

UIImage *image = [UIImage imageNamed:@"facebook.png"];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.bounds = CGRectMake( 0, 0, image.size.width, image.size.height);
[btn setImage:image forState:UIControlStateNormal];
[btn addTarget:self action:@selector(loginPressed) forControlEvents:UIControlEventTouchDragInside];
UIBarButtonItem *rbBtn = [[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.rightBarButtonItem = rbBtn;
于 2013-06-25T10:24:47.767 回答
0

试试这个代码

UIImage* image = [UIImage imageNamed:@"facebook.png"];
    CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
    UIButton *someButton = [[UIButton alloc] initWithFrame:frame];
    [someButton setBackgroundImage:image forState:UIControlStateNormal];
    [someButton addTarget:self action:@selector(facebookshare)
        forControlEvents:UIControlEventTouchUpInside];
    [someButton setShowsTouchWhenHighlighted:YES];

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

这可能对你有帮助......

于 2013-06-25T10:39:41.147 回答