Ios 自定义UIToolbar按钮没有';行不通

Ios 自定义UIToolbar按钮没有';行不通,ios,uibarbuttonitem,uitoolbar,Ios,Uibarbuttonitem,Uitoolbar,在我的xib文件中有一个bar按钮项 .h: .m: 我用按钮连接到文件的所有者,但它不工作,请帮我解决这个问题 多谢各位 到底什么不起作用 aboutToolbarButton.frame=CGRectMake(0.0,100.0,60.0,30.0) y=100?工具栏只有44像素高…这就是正在发生的事情: 使用interface builder,将UIBarButtonim链接到控制器,告诉控制器特定的UIBarButtonim是self.toolbar按钮 然后在代码中,告诉控制器sel

在我的xib文件中有一个bar按钮项

.h:

.m:

我用按钮连接到文件的所有者,但它不工作,请帮我解决这个问题


多谢各位

到底什么不起作用

aboutToolbarButton.frame=CGRectMake(0.0,100.0,60.0,30.0)


y=100?工具栏只有44像素高…

这就是正在发生的事情:

  • 使用interface builder,将UIBarButtonim链接到控制器,告诉控制器特定的UIBarButtonim是self.toolbar按钮

  • 然后在代码中,告诉控制器self.toolbarButton现在是代码创建的另一个按钮(但尚未添加到视图中),使用

  • 现在self.toolbar按钮不再是interface builder中的按钮

    因此,您认为视图中看到的按钮“不起作用”,因为您没有为该按钮指定任何选择器

    我建议您使用interface builder将iAction链接到按钮

    说到这里,您似乎不明白interface builder是如何工作的。我建议你阅读更多的教程,或者更好,请按以下步骤阅读本书:

    谢谢。。。我真是个白痴,但我把它改成(0.0,0.0,60.0,30.0),它就不起作用了。
        @property (nonatomic, retain) IBOutlet UIBarButtonItem *toolbarButton;
    
        UIButton *aboutToolbarButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [aboutToolbarButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
        [aboutToolbarButton setTitle:@"about" forState:UIControlStateNormal];
        aboutToolbarButton.titleLabel.font = [UIFont fontWithName:@"Helvetica" size:12.0f];
        [aboutToolbarButton.layer setCornerRadius:4.0f];
        [aboutToolbarButton.layer setMasksToBounds:YES];
        [aboutToolbarButton.layer setBorderWidth:1.0f];
        [aboutToolbarButton.layer setBorderColor: [[UIColor grayColor] CGColor]];
        aboutToolbarButton.frame = CGRectMake(0.0, 100.0, 60.0, 30.0);
        [aboutToolbarButton addTarget:self action:@selector(getToUserSettingsViewController) forControlEvents:UIControlEventTouchUpInside];
        self.toolbarButton = [[UIBarButtonItem alloc] initWithCustomView:aboutToolbarButton];
    
    [[UIBarButtonItem alloc] initWithCustomView:aboutToolbarButton];