我正在尝试以编程方式制作标签,并且由于某种原因它没有出现。我已经在.h文件中声明了它,这就是我在.m上的内容:
TitleLabel.textColor = [UIColor whiteColor];
TitleLabel.frame =CGRectMake(65, 30, 200, 50);
TitleLabel.textAlignment = NSTextAlignmentCenter;
TitleLabel.alpha = 1;
TitleLabel.font = [UIFont fontWithName:@"BrandonGrotesque-Black" size:23];
TitleLabel.backgroundColor = [UIColor blackColor];
TitleLabel.text = @"TEST";
任何人都可以帮我解决这个小问题。感谢
答案 0 :(得分:0)
你错过了init,这样做:
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(x,y,width,height)];
答案 1 :(得分:0)
首先,您需要使用alloc / init方法创建标签ojbect:
titleLabel = [[UILabel alloc] init];
或
titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(65, 30, 200, 50)];
最后你需要在视图上添加它:
[self.view addSubview:titleLabel];
而且,还有一点建议 - 使用CamelCase编码风格: http://en.wikipedia.org/wiki/CamelCase 最佳做法是从小写中命名类的实例,例如 titleLabel ,而不是 TitleLabel