zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Pycharm快捷键【mac版】
    程序解数独
    c++ map
    c++ vector 初始化二维数组
    二进制求和
    数组形式的加一
    坑题:最后一个单词的长度
    最大子序和:dp
    外观数列
    双指针消重复项
  • 原文地址:https://www.cnblogs.com/qqcc1388/p/6397936.html
Copyright © 2011-2022 走看看