现在的位置: 首页 > 综合 > 正文

sizeToFit的用法

2017年12月08日 ⁄ 综合 ⁄ 共 505字 ⁄ 字号 评论关闭
- (void)sizeToFitDemo
{
	
	UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(10, 40, 90, 90)];
    whiteView.backgroundColor = [UIColor whiteColor];
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 70, 20)];
	label.backgroundColor = [UIColor redColor];
    label.text = @"kkjkjkkjkjkjkjjkjkjkjjkjkkjkjkjkjk2222222222222";
    [whiteView addSubview:label];
	
    NSLog(@"the label bounds : %@", NSStringFromCGRect(label.frame));
	
    [label sizeToFit];
	
    NSLog(@"the label bounds : %@", NSStringFromCGRect(label.frame));
	
    [self.window addSubview:whiteView];
	
}

抱歉!评论已关闭.