gpt4 book ai didi

iphone - 子类化 UIToolbar 的正确方法

转载 作者:行者123 更新时间:2023-12-03 21:18:38 25 4
gpt4 key购买 nike

我第一次对 UIToolbar 进行子类化,以使用自定义 UIBarButton 创建 UIToolbar。

我正在这样做:

@interface CustomToolbar : UIToolbar

@end


@implementation CustomToolbar

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// add buttons
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"Button" style:UIBarButtonItemStyleBordered target:self action:@selector(pressSignupButton:)];

// add buttons to the array
NSArray *items = [NSArray arrayWithObjects:myButton, nil];

[self setItems:items];
}
return self;
}

@end

然后在我的 View Controller 中:

CustomToolbar *myToolbar = [[CustomToolbar alloc] init];
[self.navigationController.view addSubview:myToolbar];

问题是我可以看到工具栏,但没有按钮。为什么?

注意:我更喜欢以编程方式实现所有功能,无需 Nib 。

最佳答案

这有效吗?

CustomToolbar *myToolbar = [[CustomToolbar alloc] 
initWithFrame:CGRectMake(0,0,self.navigationController.view.frame.size.width, 44)];
[self.navigationController.view addSubview:myToolbar];

关于iphone - 子类化 UIToolbar 的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7434137/

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