美文网首页
iOS UIAlertController 的message 设

iOS UIAlertController 的message 设

作者: 攻城狮GG | 来源:发表于2019-08-09 09:23 被阅读0次

-(void)alertWithTitle:(NSString*)title andMessage:(NSString*)message{UIAlertController* alertContorller = [UIAlertControlleralertControllerWithTitle:title message:message preferredStyle:(UIAlertControllerStyleAlert)];UIView*subView1 = alertContorller.view.subviews[0];UIView*subView2 = subView1.subviews[0];UIView*subView3 = subView2.subviews[0];UIView*subView4 = subView3.subviews[0];UIView*subView5 = subView4.subviews[0];//设置title的对齐方式UILabel* titleLab = subView5.subviews[0]; titleLab.textAlignment =NSTextAlignmentLeft;//设置内容的对齐方式UILabel*mes= subView5.subviews[1]; mes.textAlignment =NSTextAlignmentRight;//设置 title 的字体颜色 大小NSDictionary* dic=@{NSForegroundColorAttributeName:[UIColororangeColor],NSFontAttributeName:[UIFontsystemFontOfSize:28],NSExpansionAttributeName:@(0.2), };NSMutableAttributedString*attributedStr=[[NSMutableAttributedStringalloc]initWithString:title attributes:dic]; [alertContorller setValue:attributedStr forKey:@"attributedTitle"];//设置 message 的字体颜色 大小NSDictionary* messageDic=@{NSForegroundColorAttributeName:[UIColorredColor],NSFontAttributeName:[UIFontsystemFontOfSize:12],NSExpansionAttributeName:@(0.2), };NSMutableAttributedString* attributedMesStr=[[NSMutableAttributedStringalloc]initWithString:message attributes:messageDic]; [alertContorller setValue:attributedMesStr forKey:@"attributedMessage"];UIAlertAction* cancelAction = [UIAlertActionactionWithTitle:@"返回"style:(UIAlertActionStyleCancel) handler:^(UIAlertAction* _Nonnull action) {NSLog(@"返回"); }];//设置字体颜色[cancelAction setValue:[UIColorpurpleColor] forKey:@"titleTextColor"];UIAlertAction* sureAction = [UIAlertActionactionWithTitle:@"继续选择"style:(UIAlertActionStyleDefault) handler:^(UIAlertAction* _Nonnull action) {NSLog(@"继续"); }];//设置字体颜色[sureAction setValue:[UIColormagentaColor] forKey:@"titleTextColor"]; [alertContorller addAction:cancelAction]; [alertContorller addAction:sureAction]; [selfpresentViewController:alertContorller animated:YEScompletion:nil];}

相关文章

网友评论

      本文标题:iOS UIAlertController 的message 设

      本文链接:https://www.haomeiwen.com/subject/jwygvqtx.html