2

uibutton を uibarbuttonitem に追加するコードを適用しましたが、問題はボタンがフレームからはみ出していることです

コードは

        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;

何が悪いのかわからないここに画像の説明を入力

4

4 に答える 4

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;
于 2013-06-17T13:05:38.040 に答える
0

UINavigationBar高さは 44、フレームを設定 (0.0、0.0、65.0、63.0)、フレームの高さを変更して収まるようにしますUINavigationBar

于 2013-06-17T13:07:22.120 に答える
0

の高さを下げてみましたCGRectMake(0.0, 0.0, 65.0,63.0)か?はい、あなたはおそらく漏れているでしょうview そしてmenuButton

また、代わりに -

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];
于 2013-06-17T13:08:37.703 に答える