【发布时间】:2014-03-04 07:29:30
【问题描述】:
嗨,我像这样以编程方式创建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 View 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 中禁用自动布局。我的答案是:stackoverflow.com/questions/21042733/…
-
我没有看到您要更改您提到的
Y值的部分... -
我试图改变这个_titleLabel的第二个参数 = [[[UILabel alloc] init] initWithFrame:CGRectMake(0.0, _photoView.frame.size.height, _photoView.frame.size.width, 100.0 )];
-
我为一个单元格使用了一个自定义类,但没有用于那个的 xib
-
如果你不想改变
UILabel的大小,为什么不玩center?
标签: ios7 uiimageview uilabel