我有一个类,当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];
}
}任何帮助都将不胜感激!
发布于 2012-04-13 11:35:37
我所做的一个快速修复完成了我想要实现的目标。
代码: if ([self isMemberOfClass:UIButton类] && self.buttonType == UIButtonTypeCustom) {
if (![[self titleLabel] text]) {
} else {
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];
}
}
}所以,基本上,所有的UIButtons都有一个带有text的titleLabel,但UITableViewCellAccessoryType没有。因此,我们成功了。这可能是一个技巧,但现在它帮助我完成了我需要的东西。
https://stackoverflow.com/questions/10134769
复制相似问题