0

当is为真时,我有一堂课会调侃UIButton's 。但是,在涉及和使用时也是如此。正在发生的事情是,由于某种原因,它正在对它们进行调配并在其后面添加自定义背景等。buttonTypeUIButtonTypeCustomUITableViewCellAccessoryCheckmarkUITableViewCellAccessoryDisclosureaccessoryType

我需要做的是检查UIButton我试图调配的是否是 aUITableViewCellAccessoryType但我不知道如何做这样的事情。

这是我用来调配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];
        }  
}

任何帮助将不胜感激!

4

1 回答 1

0

我所做的快速修复完成了我想要实现的目标。

代码: if ([self isMemberOfClass:[UIButton class]] && 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都有一个titleLabelwithtextUITableViewCellAccessoryType没有。因此,我们取得了成功。这可能是一个 hack,但现在它帮助我完成了我需要的东西。

于 2012-04-13T03:35:37.310 回答