按钮titleLabel设置为隐藏YES,触摸时重新出现

时间:2011-12-26 21:48:49

标签: iphone ios cocoa-touch

在视图控制器中,我设置了以下代码,以便最初隐藏按钮阵列组:

- (void)viewDidLoad {
    [super viewDidLoad];
    for(UIButton * noteButtonItem in noteButtonArray){
        noteButtonItem.titleLabel.hidden = YES;
        //NSLog(@"Title is %@", noteButtonItem.currentTitle);
    }
}

来自.h文件:

@property (nonatomic,retain) IBOutletCollection(UIButton) NSArray *noteButtonArray;

通过IB附加

初始隐藏工作正常,但是当我“触摸”一个按钮(在模拟器中)时,titleLabel不会保持隐藏状态。

幕后发生了什么? 有没有办法让它们保持隐藏,直到隐藏设置为YES?

2 个答案:

答案 0 :(得分:10)

UIButton个实例可以根据其状态(描述为here的状态)具有不同的配置。如果要在所有州隐藏按钮的标题标签,可以使用setTitle:forState:并将其标题设置为@"",或者您可以将颜色的Alpha属性更改为0.0f使用setTitleColor:forState:,当按钮处于所选状态时,它变为透明。

答案 1 :(得分:0)

您可以使用其中一种跟踪方法,确保即使在“触摸”后它也会保持隐藏状态。这来自UIControl类引用:

跟踪触摸和重绘控件

  • - beginTrackingWithTouch:withEvent:
  • - continueTrackingWithTouch:withEvent:
  • - endTrackingWithTouch:withEvent:
  • - cancelTrackingWithEvent:
  • 追踪财产
  • touchInside property