无法以编程方式更改UILabel的Y坐标

时间:2014-03-04 07:29:31

标签: ios7 uiimageview uilabel

嗨我以编程方式创建像这样的UILabel

`

- (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;
}`

由于

1 个答案:

答案 0 :(得分:0)

在这一行中,您使用了两种类型init

[[[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)]