UILabel 宽高自适应

- (void)loadView {

    

   CGRect appRect = [[UIScreen mainScreen] applicationFrame];

    UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(appRect), CGRectGetHeight(appRect)-CGRectGetHeight(self.navigationController.navigationBar.frame))];

    [baseView setBackgroundColor:[UIColor whiteColor]];

    self.view = baseView ;

    [baseView release];

    

    UILabel *testLabel = [[UILabel alloc]init];

    [testLabel setBackgroundColor:[UIColor clearColor]];

    [testLabel setText:@"社会抚养费一般以当地人均可支配收入作为基数,再乘以N倍系数来征收。这个N可以是1也可以是10。对于那些收入远超过这个基数的人来说,多地还规定,收入超过部分也要乘以一定的倍数来交钱。这意味着许多经济收入不错的人需要交很高的费用。"];

    testLabel.numberOfLines = 0;

    [testLabel setFont:[UIFont systemFontOfSize:12]];

    [testLabel setTextColor:[UIColor redColor]];

    CGSize maxSize = CGSizeMake(240, 200);

    CGSize  testLabelFrame = [testLabel.text sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:maxSize lineBreakMode:testLabel.lineBreakMode];

    [testLabel setFrame:CGRectMake(0, 0, maxSize.width, testLabelFrame.height)];

    [self.view addSubview:testLabel];

    [testLabel release];

    

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值