我正在开发一个应用程序。我尝试使用以下代码将 UIIMage 添加到 UIAlertView,
UIAlertView *alert = [[UIAlertView alloc] initWithTitle"Instruction"
message"lease TAP on Screen to Continue."
delegate:self
cancelButtonTitle"OK"
otherButtonTitles:nil];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 50, 32, 32)];
UIImage *img = [UIImage imageNamed"pendingImg.png"];
[imageView setImage:img];
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
[alert setValue:imageView forKey"accessoryView"];
}else{
[alert addSubview:imageView];
}
[alert show];
我的图像尺寸为 32 × 32 像素。我收到如图所示的警报,
我应该为此图像添加约束吗?还是要做什么?
Best Answer-推荐答案 strong>
可以将imageView contentMode 设置为UIViewContentModeScaleAspectFit ,
UIAlertView *alert = [[UIAlertView alloc] initWithTitle"Instruction"
message"lease TAP on Screen to Continue."
delegate:self
cancelButtonTitle"OK"
otherButtonTitles:nil];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 50, 32, 32)];
UIImage *img = [UIImage imageNamed"pendingImg.png"];
imageView.contentMode = UIViewContentModeScaleAspectFit;
[imageView setImage:img];
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
[alert setValue:imageView forKey"accessoryView"];
}else{
[alert addSubview:imageView];
}
[alert show];
可能Anbu.Karthik建议的链接评论对您也有帮助。
关于ios - 将 UIImage 添加到 UIAlertView 未按预期工作,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/42484813/
|