0
喜林以編程方式創建一個UILabel
這樣無法更改的UILabel的Y cordinate編程
`
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[[UILabel alloc] init] initWithFrame:CGRectMake(0.0, _photoView.frame.size.height, _photoView.frame.size.width, 100.0)];
// _titleLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
_titleLabel.backgroundColor =[UIColor clearColor];
_titleLabel.textColor = [UIColor whiteColor];
_titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
_titleLabel.textAlignment = NSTextAlignmentRight;
[self addSubview:_titleLabel];
}
return _titleLabel;
}`
這_photoView
是一個UIImageView
我已經創建。我想更改UILabel
查看Y值。但問題是,當我改變這第二個參數標籤y位置不變。任何人都可以告訴其原因。
而且這是我創建的ImageView的
`
- (UIImageView *)photoView {
if (!_photoView) {
_photoView = [[UIImageView alloc] init];
_photoView.contentMode = UIViewContentModeScaleAspectFill;
_photoView.clipsToBounds = YES;
_photoView.layer.cornerRadius = 5;
_photoView.clipsToBounds = YES;
[self addSubview:_photoView];
}
return _photoView;
}`
感謝
確保在Interface Builder中禁用自動佈局。我的回答就此:http://stackoverflow.com/questions/21042733/programmatically-moving-a-uilabel-in-a-xib-file/21042987#21042987 – nzs
我沒有看到你正在改變的部分你提到的'Y'值... – holex
我試着改變這個_titleLabel = [[[UILabel alloc] init]的第二個參數initWithFrame:CGRectMake(0.0,_photoView.frame.size.height,_photoView.frame.size.width ,100.0)]; – user2889249