zoukankan      html  css  js  c++  java
  • ios 根据字符串中的逗号分行显示

    //自动计算高宽

    • (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize
      {
      NSDictionary *attrs = @{NSFontAttributeName : font};
      return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
      }
    • (void)viewDidLoad {
      [super viewDidLoad];
      NSString *strname = @"123456,000000,333333,223344";

    pragma mark 判断是否包含逗号

    if([strname rangeOfString:@","].location !=NSNotFound){
    

    pragma mark 替换逗号用换行

        strname=[strname stringByReplacingOccurrencesOfString:@"," withString:@"
    "];
    }
    UILabel *name = [[UILabel alloc]init];
    name.text = strname;
    name.numberOfLines = 0;
    CGSize size = [self sizeWithText:name.text font:[UIFont systemFontOfSize:13] maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
    name.backgroundColor=[UIColor redColor];
    name.font=[UIFont systemFontOfSize:13];
    name.frame=CGRectMake(30,200,size.width,size.height);
    [self.view addSubview:name];
    

    }

  • 相关阅读:
    1026. 程序运行时间(15)
    C语言字符串/数组去重
    1025. 反转链表 (25)
    1024. 科学计数法 (20)
    1023. 组个最小数 (20)
    1022. D进制的A+B (20)
    1021. 个位数统计 (15)
    1020. 月饼 (25)
    前端001/正则表达式
    SSM001/构建maven多模块项目
  • 原文地址:https://www.cnblogs.com/shao621/p/5278706.html
Copyright © 2011-2022 走看看