ios7.1 setButtonImage( setimage跟创建button不在一方法体中的情况)

在ios7.0及以前


+(id)getButton:(NSString *)selectImageName UnselectImageName:(NSString *)unselectImageName frame:(CGRect)frame

{

    NDTSelectButton *button = [NDTSelectButton buttonWithType:UIButtonTypeCustom];

    button.frame = frame;

    button.selectImageName  = selectImageName;

    button.unSelectImageName = unselectImageName;

    [button setBackgroundImage:[UIImage imageNamed:button.selectImageName] forState:UIControlStateNormal];

    [button setBackgroundImage:[UIImage imageNamed:button.selectImageName] forState:UIControlStateHighlighted];

    return button;

}


-(void)setIsSelected:(BOOL)isSelected

{

    _isSelected = isSelected;

    if (_isSelected)

    {

        [self setBackgroundImage:[UIImage imageNamed:self.selectImageName] forState:UIControlStateNormal];

        [self setBackgroundImage:[UIImage imageNamed:self.selectImageName] forState:UIControlStateHighlighted];

    }else

    {

        [self setBackgroundImage:[UIImage imageNamed:self.unSelectImageName] forState:UIControlStateNormal];

        [self setBackgroundImage:[UIImage imageNamed:self.unSelectImageName] forState:UIControlStateHighlighted];

    }

    

}

同时调用上述两个方法(setimage跟创建button不在一方法体中的情况),是可以正常给button添加图片和实现换图功能的 但是7.1就不行,只能在添加

self.enabled = NO;

    self.enabled = YES;

才能正常运行

具体代码如下

+(id)getButton:(NSString *)selectImageName UnselectImageName:(NSString *)unselectImageName frame:(CGRect)frame

{

    NDTSelectButton *button = [NDTSelectButton buttonWithType:UIButtonTypeCustom];

    button.frame = frame;

    button.selectImageName  = selectImageName;

    button.unSelectImageName = unselectImageName;

    [button setBackgroundImage:[UIImage imageNamed:button.selectImageNameforState:UIControlStateNormal];

    [button setBackgroundImage:[UIImage imageNamed:button.selectImageNameforState:UIControlStateHighlighted];

    return button;

}


-(void)getSelectButton:(NSString *)selectImageName UnselectImageName:(NSString *)unselectImageName frame:(CGRect)frame

{

//    NDTSelectButton *button = [NDTSelectButton buttonWithType:UIButtonTypeCustom];

    self.frame = frame;

    self.selectImageName  = selectImageName;

    self.unSelectImageName = unselectImageName;

    NSLog(@"button.selectImageName%@---%@",self.selectImageName,self.unSelectImageName);

}

具体原因未知

你可能感兴趣的:(ios7.1 setButtonImage( setimage跟创建button不在一方法体中的情况))