【发布时间】:2012-04-13 03:15:33
【问题描述】:
当buttonType 是UIButtonTypeCustom 为真时,我有一个类会混淆UIButton。
然而,当涉及到UITableViewCellAccessoryCheckmark 和UITableViewCellAccessoryDisclosure 时也是如此。正在发生的事情是,出于某种原因,它正在调整它们并在 accessoryType 后面添加自定义背景等。
我需要做的是检查我试图调配的UIButton 是否是UITableViewCellAccessoryType,但我不知道如何做这样的事情。
这是我用来调配UIButton 的函数的内部结构。
if ([self isMemberOfClass:[UIButton class]] && self.buttonType == UIButtonTypeCustom) {
UIImage *upImage = [theme rectButtonUp], *downImage = [theme rectButtonDown];
UIColor *upColor = [theme rectButtonUpTextColor], *downColor = [theme rectButtonDownTextColor];
/* If the highlighted title is set to _theme_asdf, look for a custom
* button image called "asdf" and use that. Clear out this highlighted
* title string. */
NSString *hlTitle = [self titleForState:UIControlStateHighlighted];
if ([hlTitle isEqualToString:@"_theme_add"] || [hlTitle isEqualToString:@"Add"]) {
upImage = [theme rectButtonUpAdd];
downImage = [theme rectButtonDownAdd];
} else if ([hlTitle isEqualToString:@"_theme_remove"]) {
upImage = [theme rectButtonUpRemove];
downImage = [theme rectButtonDownRemove];
} else {
upImage = [theme rectButtonUp];
downImage = [theme rectButtonDown];
}
[self setTitle:nil forState:UIControlStateHighlighted];
upColor = [theme rectButtonUpTextColor];
downColor = [theme rectButtonDownTextColor];
[self setBackgroundImage:upImage forState:UIControlStateNormal];
[self setBackgroundImage:downImage forState:UIControlStateHighlighted];
[self setBackgroundImage:downImage forState:UIControlStateSelected];
if (upColor) {
[self setTitleColor:upColor forState:UIControlStateNormal];
[self setTitleColor:[upColor colorByLighteningTo:0.5f] forState:UIControlStateDisabled];
}
if (downColor) {
[self setTitleColor:downColor forState:UIControlStateHighlighted];
[self setTitleColor:downColor forState:UIControlStateSelected];
}
}
任何帮助将不胜感激!
【问题讨论】:
-
子类化 UIButton 并在您想要混合时使用该类以便只混合新类?
标签: objective-c uibutton uitableview swizzling