Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 具有contentMode UIViewContentModeScaleSpectFit的UIImageView的UILabel_Ios_Contentmode - Fatal编程技术网

Ios 具有contentMode UIViewContentModeScaleSpectFit的UIImageView的UILabel

Ios 具有contentMode UIViewContentModeScaleSpectFit的UIImageView的UILabel,ios,contentmode,Ios,Contentmode,我需要在UIImageView顶部设置一个具有自定义背景颜色的标签。问题是,我希望它的宽度是图像视图中的图像的精确大小。这是迄今为止的代码: UIImageView *pictureV = [[UIImageView alloc] initWithFrame:CGRectMake(pictureX, 0, pictureSize.width, pictureSize.height)]; pictureV.image = self.picture.image; pictureV.contentMo

我需要在UIImageView顶部设置一个具有自定义背景颜色的标签。问题是,我希望它的宽度是图像视图中的图像的精确大小。这是迄今为止的代码:

UIImageView *pictureV = [[UIImageView alloc] initWithFrame:CGRectMake(pictureX, 0, pictureSize.width, pictureSize.height)];
pictureV.image = self.picture.image;
pictureV.contentMode = UIViewContentModeScaleAspectFit;
以及标签:

UILabel *lblName = [[UILabel alloc]init];
lblName.backgroundColor=[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.6];
lblName.frame = CGRectMake(pictureV.bounds.origin.x, pictureV.bounds.origin.y + pictureV.bounds.size.height - 30, self.picture.image.size.width, 30);
[lblName setText:self.pictureNote.text];
[lblName setTextAlignment:UITextAlignmentCenter];
[lblName setTextColor:[UIColor whiteColor]];
[pictureV addSubview:lblName]

将contentMode设置为UIViewContentModeScaleSpectFit时,某些图像比我的UIImageView小,并且我似乎无法使标签的宽度保持相同的大小。

如果使用UIViewContentModeScaleSpectFit,图像将不会具有UIImage视图的完整大小。 而不是将pictureV的contentMode属性设置为UIViewContentModeScaleToFill,
然后图像将采用图像视图的整个大小

如果使用UIViewContentModeScaleAspectFit,图像将不会采用UIImage视图的全部大小。 而不是将pictureV的contentMode属性设置为UIViewContentModeScaleToFill, 然后,图像将采用您的imageView的整个尺寸