嘿,我编写了一个类 (A),它继承了一些功能,包括导航按钮的实现。A类既有查看模式又有编辑模式,我只想在编辑模式下显示按钮。到目前为止,我无法删除此按钮,并且我真的不想创建另一个类来进行编辑。
其他类也继承了这个功能,所以我真的不想和父母搞混。
我用来创建按钮的代码如下:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *buttonImage = [UIImage imageNamed:@"button.png"];
[button addTarget:self
action:@selector(buttonPressed:)
forControlEvents:UIControlEventTouchUpInside];
button.bounds = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setTitle:NSLocalizedString(@"BUTTON", @"")
forState:UIControlStateNormal];
LPRBSLabel *buttonLabel = [[LPRBSLabel alloc] initWithStyle:UICustomeButtonTitle];
[button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 0.0, -5.0, 0.0)];
button.titleLabel.font = buttonLabel.font;
[button setTitleColor:buttonLabel.textColor forState:UIControlStateNormal];
[buttonLabel release];
UIBarButtonItem *barLeftInfoButton = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = barLeftInfoButton;
[barLeftInfoButton release];