我有一个View,它有一个UIImageView和UILabel
@interface NetStatusView()
@property (nonatomic,strong) UIImageView *statusImageView;
@property (nonatomic,strong) UILabel *statusLabel;
@end
然后我在设置属性的时候,报错了:
- (void)layoutSubviews{
[super layoutSubviews];
self.statusLabel.centerY = self.bounds.size.height * .5f;//这行报错了
self.statusImageView.right = self.bounds.size.width;
self.statusImageView.centerY = self.bounds.size.height * .5f;
}
报错是:
'NSInvalidArgumentException', reason: '-[UILabel setCenterY:]: unrecognized selector sent to instance 0x7feb3bd76bb0'
@不如笑归去 同学所说的没有初始化,应该是我没有贴代码,不好意思,贴上:
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}
- (void)setup{
self.backgroundColor = [UIColor clearColor];
_statusImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
_statusImageView.hidden = YES;
_statusLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_statusLabel.hidden = YES;
_statusLabel.backgroundColor = [UIColor clearColor];
_statusLabel.textColor = UIColorFromRGB(0xffffff);
_statusLabel.font = [UIFont systemFontOfSize:16.f];
[self addSubview:_statusImageView];
[self addSubview:_statusLabel];
}
本人ios新手,这是对着某个教程写的,感觉没问题啊,请问这个问题有什么思路吗?(如果需要贴更多信息,请随便提)
[UILabel setCenterY:] 说的是UIlabel里面没有这个Set方法, 但是有setCenter方法的, 你可以设置下这个Label的Center试试 CGpoint类型的 还有,我没看到你初始化的地方