如果您添加带有属性字符串或常规字符串的标签,我认为这不会对视图产生影响。您只需添加Subview:MyLabel
查看下面的代码。
//setup the testview
UIView *testView = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 100, 100)];
[testView setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:testView];
//setup the label
UILabel *txtLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
[txtLabel setBackgroundColor:[UIColor redColor]];
NSDictionary *attrib = @{NSForegroundColorAttributeName : [UIColor blueColor]};
NSMutableAttributedString *attribString = [[NSMutableAttributedString alloc]initWithString:@"test" attributes:attrib];
txtLabel.attributedText = attribString;
[testView addSubview:txtLabel]; //add the label to the testview