【问题标题】:How to change button borderColor in UICollectionReusableView when cell alloced分配单元格时如何更改 UICollectionReusableView 中的按钮边框颜色
【发布时间】:2014-11-18 14:36:35
【问题描述】:

我有一个带有按钮的 UICollectionReusableView,当用户点击按钮时,我想更改背景颜色和边框颜色。 BackgroundColor 已更改,但 borderColor 未更改。
代码:

@implementation ClothesTopView

//==============================================================================

- (void)configCell:(id<ClothesTopViewDelegate>)delegate
{
    _clothesTopViewDelegate = delegate;
    for (UIButton *button in _topButtonCollection)
    {
        button.layer.cornerRadius = 2;
        button.layer.borderWidth = 1.f;
        button.layer.borderColor = [UIColor whiteColor].CGColor;
    }
}

//==============================================================================

- (IBAction)topButtonAction:(UIButton *)sender
{
    for (UIButton *button in _topButtonCollection)
    {
        if (button == sender)
        {
            sender.layer.borderColor = [UIColor colorWithRed:226/255.f green:71/255.f blue:49/255.f alpha:1.f].CGColor;
            sender.backgroundColor = [UIColor colorWithRed:226/255.f green:71/255.f blue:49/255.f alpha:1.f];
        }
        else
        {
            button.layer.borderColor = [UIColor whiteColor].CGColor;
            button.backgroundColor = [UIColor clearColor];
        }
    }
    [_clothesTopViewDelegate topViewButtonDidPressWithTitle:sender.titleLabel.text];
}

//=========================================================================

@end

【问题讨论】:

  • 我也有同样的问题。等待帮助

标签: ios uibutton uicollectionreusableview


【解决方案1】:

应用更改后尝试调用此方法

 [self setNeedsDisplay];

这将告诉 iOS 重绘单元格并且你的边框颜色应该改变。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    • 1970-01-01
    • 2016-02-11
    • 2019-08-12
    • 1970-01-01
    相关资源
    最近更新 更多