UIAlterController显示内容居左显示的方法

2018-12-21  本文已影响0人  悲催的小白兔

有时候,会有这样的需求,解决办法来了。类似,你可以修改title,或者各个按钮的样式。

NSString *message = @"想要居左显示的内容~~~";
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
//关键代码
[self findSubView:alert.view condition:message];

[alert addAction:[UIAlertAction actionWithTitle:@"前往更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {}]];
[self presentViewController:alert animated:YES completion:nil];

- (void)findSubView:(UIView *)view condition:(NSString *)str {
    for (NSUInteger i = 0; i < view.subviews.count; i++) {
        UIView *subView = view.subviews[i];
        if ([subView isKindOfClass:[UILabel class]]) {
            UILabel *label = (UILabel *)subView;
            if ([label.text isEqualToString:str]) {
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    label.textColor = [UIColor redColor];
                    label.font = [UIFont systemFontOfSize:14];
                    label.textAlignment = NSTextAlignmentLeft;
                });
                break;
            }
        }
        [self findSubView:subView condition:str];
    }
}
上一篇 下一篇

猜你喜欢

热点阅读