iOS 11自定义UIAlertView无法正常渲染

时间:2017-10-12 19:03:20

标签: ios objective-c uialertview uiactionsheet

所以我有和app有一个自定义UIAlertView(根据自定义我的意思是以编程方式在底部添加UILabel)。它适用于iOS< 11,但在iOS 11中它失败了。因此,在iOS 10上它可以正常工作(左)但在iOS 11(右)中失败并使用相同的代码iOS 10 vs iOS 11

这是我用来制作自定义UAlertView的代码。有什么想法吗?

SessionManager *sessionMgr = [SessionManager sharedManager];
NSString *saludoStr = [NSString stringWithFormat:@"¡Bienvenido %@!",self.datosPersonalesResponse.nombre];
NSString *mailStr = [sessionMgr getUserEmail];
NSString *mensajeStr = [NSString stringWithFormat:@"Te hemos enviado un email de \nactivación de cuenta a: \n\n%@\n\nActivá tu cuenta para recibir alertas,\n avisos recomendados y postularte a \nempleos.\n",mailStr];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:saludoStr message:@"" delegate:self cancelButtonTitle:@"Cerrar" otherButtonTitles:@"No lo recibí", nil];
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
lbl.numberOfLines= 0;

[lbl setFont:[UIFont fontWithName:@"OpenSans" size:13]];
[lbl setTextColor:[UIColor colorWithRed:146/255.0f green:146/255.0f blue:146/255.0f alpha:1.0]];

NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:mensajeStr];
[attributedStr addAttribute:NSFontAttributeName
                      value:[UIFont fontWithName:@"OpenSans-Semibold" size:16]
                      range:NSMakeRange(56,[mailStr length])];

[attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(56,[mailStr length])];

lbl.attributedText = attributedStr;
lbl.textAlignment = NSTextAlignmentCenter;
[alert setValue:lbl forKey:@"accessoryView"];
[alert show];

1 个答案:

答案 0 :(得分:2)

UIAlertView 已弃用。请考虑将 UIAlertController full details here一起使用。