我有一个名为 Ntoolbar 的工具栏。它包含一些 UILabel,并有一个方法“insertTitle:(NSString) *title”:
- (void) insertTitle:(NSString *)title{
UILabel *newlabel = [ [UILabel alloc ] initWithFrame:CGRectMake((self.bounds.size.width / 2), 0.0, 150.0, 43.0) ];
newlabel.textAlignment = UITextAlignmentCenter;
newlabel.textColor = [UIColor whiteColor];
newlabel.backgroundColor = [UIColor darkGrayColor];
newlabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(14.0)];
[_ribbon_title addSubview:newlabel];
newlabel.text = [NSString stringWithFormat: @"%@", title];
}
在 ViewController 中,我有一个出口:@property (strong, nonatomic) IBOutlet NToolBar *nToolBar; 而在 ViewDidLoad() 中,我调用这个方法来添加一个 UILabel
- (void)viewDidLoad
{
[super viewDidLoad];
[_nToolBar insertTitle:@"edit"];
}
图片:添加新标签之前:http: //nt9.upanh.com/b2.s32.d2/9a3ff99d74de684dcc2075e98274a6e0_52281369.screenshot20130103at4.png
添加新标签后,旧的UILabel被新的UILabel覆盖了吗?
http://nt5.upanh.com/b1.s33.d1/e6dd9ef7e8748dc445d71a5cc28a0d3c_52281635.screenshot20130103at4.png。
如何在它们之间添加约束?