iOS UIAlertView 文字对其方式 文字大小 设置方法

- (void) willPresentAlertView:(UIAlertView *)alertView
{
   for (UIView *subViewin alertView.subviews)
    {
       UILabel *tmpLabel = (UILabel *)subView;
        tmpLabel.textAlignment =NSTextAlignmentLeft;
    }
}

在iOS7.0之前通过以上方法进行设置Label对其和文字大小,但是到了iOS7.0以后以上方法都无效了

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"测试换行"
                                                               message:nil
                                                              delegate:self
                                                     cancelButtonTitle:nil
                                                     otherButtonTitles:@"知道了", nil];

            CGSize size = [self.messageString sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(240, 1000) lineBreakMode:NSLineBreakByTruncatingTail];
            
            UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 240, size.height)];
            textLabel.font = [UIFont systemFontOfSize:15];
            textLabel.textColor = [UIColor blackColor];
            textLabel.backgroundColor = [UIColor clearColor];
            textLabel.lineBreakMode = NSLineBreakByWordWrapping;
            textLabel.numberOfLines = 0;
            textLabel.textAlignment = NSTextAlignmentLeft;
            textLabel.text = self.messageString;
            [tmpAlertView setValue:textLabel forKey:@"accessoryView"];
            [alertView show];

iOS7.0 通过KVC的方式重写accessoryView的方法来替换系统的UILabel

转载于:https://www.cnblogs.com/qqcc1388/p/6397936.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值