我想让我的 UILabel 在叠加层中水平和垂直居中显示,并且我希望叠加层 UIView(在时髦的 lorem ipsum 文本后面带有浅色 alpha 的黑色区域)调整大小以给我 10 个像素的填充顶部和底部,但仍会自动拉伸其宽度。谁能指出我正确的方向?我想让它尽可能动态。
这是我必须让它看起来像这样:
descView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, 160)];
descView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
descView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
descLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 600, 120)];
descLabel.center = CGPointMake(self.view.bounds.size.width/2, descView.bounds.size.height/2);
descLabel.backgroundColor = [UIColor clearColor];
descLabel.opaque = NO;
descLabel.textAlignment = UITextAlignmentCenter;
descLabel.text = currentPhoto.desc;
descLabel.numberOfLines = 5;
descLabel.textColor = [UIColor whiteColor];
descLabel.autoresizingMask = UIViewAutoresizingFlexibleMargins;
CGRect frame = descLabel.frame;
frame.origin.x = (descView.frame.size.width - descLabel.frame.size.width)/2;
descLabel.frame = frame;
[self.view addSubview:descView];
[descView addSubview:descLabel];