我试图将图像放在uilabel后面,并且两者都需要大约相同的高度(uiimageview稍微大一点以围绕uilabel)并且我在cgrectmake中给出了两个相同的高度但是uiimageview仍然比uilabel小即使它们设置在同一高度。请帮助!代码:
UILabel *labelEntry = [[UILabel alloc]init];
labelEntry.numberOfLines = 0;
labelEntry.text = entry;
CGSize expectedLabelSize = [entry sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:CGSizeMake(300.f, FLT_MAX) lineBreakMode:NSLineBreakByWordWrapping];
CGRect lblFrame = CGRectMake(13, 30, 320, expectedLabelSize.height);
labelEntry.frame = lblFrame;
labelEntry.lineBreakMode = NSLineBreakByWordWrapping;
labelEntry.font = [UIFont systemFontOfSize: 17.0];
labelEntry.textAlignment = NSTextAlignmentCenter;
labelEntry.backgroundColor = [UIColor clearColor];
UIImageView *backgroundImage = [[UIImageView alloc]initWithFrame:CGRectMake(13, 30, 320, expectedLabelSize.height)];
backgroundImage.image = [UIImage imageNamed:@"postl.png"];
[scrollView addSubview:backgroundImage];
答案 0 :(得分:1)
从你的图像(postl.png)我可以注意到,有阴影效果应用于图像。通过为 imageview &设置背景颜色尝试一次。你可以看到应用图像的阴影。之后您可以相应地调整框架
答案 1 :(得分:0)
post1.png的大小是多少?如果它与CGRect的尺寸不同,则需要拉伸它。这将包括更改您的UIImageView的contentMode并可能创建一个可伸缩的图像。