首页 > 代码库 > 内容自适应UILabel
内容自适应UILabel
xcode 6.1
File-New-Project..
iOs-Application-Simple View Application
代码:
- (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];
}
内容自适应UILabel
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。