在 View Controller 中,我设置了以下代码来初始隐藏按钮数组组:
- (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?
最佳答案
UIButton
实例可以有不同的配置,具体取决于它们的状态(状态描述 here )。如果您想在所有状态下隐藏按钮的标题标签,您可以使用 setTitle:forState:
并将其标题设置为 @""
,或者您可以更改使用 setTitleColor:forState:
将颜色的 alpha 属性设置为 0.0f
,以便当按钮处于所选状态时它变得透明。
关于iphone - 按钮 titleLabel 设置为隐藏 YES,触摸时重新出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8639345/