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];

    

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章