通过IBOutlets自定义UITableViewCell中的UIComponents

时间:2018-04-11 07:34:13

标签: ios objective-c iphone uitableview

我已经使用UITableViewCell制作了xib,我已经在我的自定义UIView课程中制作了IBoutlet并制作了tableViewCell。我想设置UIView的边框颜色。

tableViewCell.h中的代码:

@property (weak, nonatomic) IBOutlet UIView *circleView;

tableViewCell.m

#import "OUSTProfileTableViewCell.h"

@implementation OUSTProfileTableViewCell
//@synthesize circleView = _circleView;

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        self.circleView.layer.cornerRadius = 3; // this value vary as per your desire
        self.circleView.layer.masksToBounds = YES;
        self.circleView.layer.borderWidth = 2.0;
        self.circleView.layer.borderColor = (__bridge CGColorRef _Nullable)([UIColor lightGrayColor]);
    }
    return self;
}


@end

但它不起作用。

1 个答案:

答案 0 :(得分:0)

将代码置于

 - (void)awakeFromNib {
  [super awakeFromNib];
  // Initialization code

    self.circleView.layer.cornerRadius = 3; // this value vary as per your desire
    self.circleView.layer.masksToBounds = YES;
    self.circleView.layer.borderWidth = 2.0;
    self.circleView.layer.borderColor = [UIColor lightGrayColor].CGColor;

 }