UIButton摆动导致UITableViewCellAccessoryType的问题



我有一个类,当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];
        }  
}

任何帮助将不胜感激!

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

法典: 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都与texttitleLabel,但UITableViewCellAccessoryType没有。因此,我们有成功。这可能是一个黑客,但现在它帮助我完成了我需要的东西。

相关内容

  • 没有找到相关文章

最新更新