0
我想創建一個適合他內容的UIView。內容是帶有動態文本的UILabel。根據內容適應高度的UIView - Objective-c
UIView *myview = [ [UIView alloc ] initWithFrame:CGRectMake(10.0, 10.0, 700.0, 100.0)];
myview.backgroundColor = [UIColor redColor];
[self.view addSubview:myview];
UILabel *myLabel = [ [UILabel alloc ] initWithFrame:CGRectMake(10.0, 10.0, 500.0, 43.0) ];
myLabel.textAlignment = UITextAlignmentLeft;
myLabel.textColor = [UIColor whiteColor];
myLabel.backgroundColor = [UIColor blackColor];
myLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(36.0)];
[myView addSubview:myLabel];
myLabel.numberOfLines = 0;
myLabel.text = @"This is an UILabel. This is an UILabel. This is an UILabel. This is an UILabel. This is an UILabel. This is an UILabel. This is an UILabel. ";
[myLabel sizeToFit];
我附上截圖:
差不多!這沒關係,但它不能保證保證金。看看:http://i54.tinypic.com/15gpmy8.png – HispaJavi 2011-02-02 12:10:12