2014-03-04 12 views
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; 
}` 

感謝

+0

確保在Interface Builder中禁用自動佈局。我的回答就此:http://stackoverflow.com/questions/21042733/programmatically-moving-a-uilabel-in-a-xib-file/21042987#21042987 – nzs

+0

我沒有看到你正在改變的部分你提到的'Y'值... – holex

+0

我試着改變這個_titleLabel = [[[UILabel alloc] init]的第二個參數initWithFrame:CGRectMake(0.0,_photoView.frame.size.height,_photoView.frame.size.width ,100.0)]; – user2889249

回答

0

在這一行,你已經使用了兩種類型的初始化

[[[UILabel alloc] init] initWithFrame:CGRectMake(0.0, _photoView.frame.size.height, _photoView.frame.size.width, 100.0)] 

改變這一行

[[UILabel alloc] initWithFrame:CGRectMake(0.0, _photoView.frame.size.height, _photoView.frame.size.width, 100.0)]