我有一个UIButton,其状态为正常/突出显示的标题应与其容器对象的属性保持同步。
如何使用字符串属性为特定状态绑定按钮标题?
编辑:
我知道使用RACObserve并在subcribeNext块中更改按钮标题是一种解决方案。
我正在寻找更专门为UIButton设计的东西,例如:
RACBindButtonTitle(button, property, state1, state2);
我不知道是否有这样的“ RAC糖”。
如果您的意思是将它们与一个属性同步,则如下所示:
[RACAble(self.buttonTitle) subscribeNext:^(NSString *newTitle) {
NSString *normalTitle = [NSString stringWithFormat:@"Normal %@", newTitle];
NSString *highlightedTitle = [NSString stringWithFormat:@"Highlighted %@", newTitle];
[self.button setTitle:normalTitle forState:UIControlStateNormal];
[self.button setTitle:highlightedTitle forState:UIControlStateHighlighted];
}];
如果您的意思是有两个属性,则如下所示:
[RACAble(self.normalButtonTitle) subscribeNext:^(NSString *newTitle) {
[self.button setTitle:newTitle forState:UIControlStateNormal];
}];
[RACAble(self.highlightedButtonTitle) subscribeNext:^(NSString *newTitle) {
[self.button setTitle:newTitle forState:UIControlStateHighlighted];
}];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句