xcode 6.1

File-New-Project..

iOs-Application-Simple View Application

内容自适应UILabel

代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    UILabel *labelLoginname = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)];
    //[labelLoginname setNumberOfLines:0];
    NSString *s = @"账号:";
    UIFont *font = [UIFont fontWithName:@"Arial" size:15];
    CGSize size = CGSizeMake(0,0);

    NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:15]};
    CGSize labelsize = [s boundingRectWithSize:size options: NSStringDrawingUsesFontLeading  attributes:attribute context:nil].size;
    
    labelLoginname.frame = CGRectMake(80.0, 80.0, labelsize.width, labelsize.height);
    labelLoginname.backgroundColor = [UIColor whiteColor];
    labelLoginname.textColor = [UIColor blackColor];
    labelLoginname.text = s;
    labelLoginname.font = font;
    
    [self.view addSubview:labelLoginname];
}

 

相关文章:

  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
  • 2022-12-23
相关资源
相似解决方案