leftbarbuttonitem出框架

时间:2013-06-17 13:01:40

标签: ios

我已经应用了一个代码来向uibarbuttonitem添加一个uibutton,问题是按钮是否已经出现了框架

代码是

        a1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [a1 setFrame:CGRectMake(0.0f, 0.0f, 65.0f, 63.0f)];
    [a1 addTarget:self.slideMenuController action:@selector(toggleMenu) forControlEvents:UIControlEventTouchUpInside];
    [a1 setImage:[UIImage imageNamed:@"menu-enable-bt.png"] forState:UIControlStateNormal];

    UIView *view =[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 65.0,63.0) ];
    [view addSubview:a1];

    menuButton = [[UIBarButtonItem alloc] initWithCustomView:view];


    rootViewController.navigationItem.leftBarButtonItem = menuButton;

我不知道什么是错enter image description here

4 个答案:

答案 0 :(得分:0)

试试这个..

 a1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [a1 setFrame:CGRectMake(0.0f, 0.0f, 30.0f, 30.0f)];
    [a1 addTarget:self.slideMenuController action:@selector(toggleMenu) forControlEvents:UIControlEventTouchUpInside];
    [a1 setImage:[UIImage imageNamed:@"menu-enable-bt.png"] forState:UIControlStateNormal];

    UIView *view =[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 35.0,35.0) ];
    [view addSubview:a1];

    menuButton = [[UIBarButtonItem alloc] initWithCustomView:view];


    rootViewController.navigationItem.leftBarButtonItem = menuButton;

答案 1 :(得分:0)

UINavigationBar高度为44,您设置框架(0.0,0.0,65.0,63.0),更改框架高度以适合UINavigationBar

答案 2 :(得分:0)

您是否尝试降低CGRectMake(0.0, 0.0, 65.0,63.0)的高度?是的,你可能会泄漏viewmenuButton

也代替 -

a1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [a1 setFrame:CGRectMake(0.0f, 0.0f, 65.0f, 63.0f)];
    [a1 addTarget:self.slideMenuController action:@selector(toggleMenu) forControlEvents:UIControlEventTouchUpInside];
    [a1 setImage:[UIImage imageNamed:@"menu-enable-bt.png"] forState:UIControlStateNormal];

    UIView *view =[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 65.0,63.0) ];
    [view addSubview:a1];

    menuButton = [[UIBarButtonItem alloc] initWithCustomView:view];

你可以给menuButton = [[UIBarButtonItem alloc] initWithCustomView:a1];然后 -

rootViewController.navigationItem.leftBarButtonItem = menuButton;

[menuButton release];

答案 3 :(得分:0)

试试这个......

UIButton * a1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [a1 setFrame:CGRectMake(0.0f, 0.0f, 65.0f, 33.0f)];
    [a1 addTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];
    [a1 setImage:[UIImage imageNamed:@"sc.png"] forState:UIControlStateNormal];


   UIBarButtonItem* menuButton = [[UIBarButtonItem alloc] initWithCustomView:a1];


    self.navigationItem.leftBarButtonItem = menuButton;

sample refer here