gpt4 book ai didi

ios - 将 UIImage 添加到 UIAlertView 未按预期工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:25:21 26 4
gpt4 key购买 nike

我正在开发一个应用程序。我尝试使用以下代码将 UIIMage 添加到 UIAlertView,

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Instruction"
message:@"Please 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 像素。我收到如图所示的警报,

Alert

我应该给这个图像添加约束吗?或者还有什么要做的?

最佳答案

您可以将 imageView contentMode 设置为 UIViewContentModeScaleAspectFit,

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Instruction"
message:@"Please 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];

enter image description here

可能 Anbu.Karthik 建议的链接评论对您也有帮助。

关于ios - 将 UIImage 添加到 UIAlertView 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42484813/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com