所以我不知道以任何方式绘制文本或字符串而是UILabel。所以我初始化了标签,但它一直在崩溃我的应用程序。
以下是初始化标签并导致崩溃的方法:
- (void)setupScore {
scoreLabel = [NSString stringWithFormat:@"%d", score]; scoreLabel.frame = CGRectMake(262, 250, 100, 40); [scoreLabel setText: scoreString]; //normally you'll want a transparent background for your label scoreLabel.backgroundColor = [UIColor clearColor]; //you can use non-standard fonts [scoreLabel setFont:[UIFont fontWithName:@"TimesNewRoman" size: 1.0f]]; //change the label's text color scoreLabel.textColor = [UIColor whiteColor]; //add it to your view scoreLabel.transform = CGAffineTransformMakeRotation(89.53); [self addSubview:scoreLabel]; }
- (void)setupPausedLabel {
pausedLabel = [NSString stringWithFormat:@"Tap To Resume"]; pausedLabel.frame = CGRectMake(262, 250, 100, 40); [pausedLabel setText: @"Tap To Resume"]; //normally you'll want a transparent background for your label pausedLabel.backgroundColor = [UIColor clearColor]; //you can use non-standard fonts [pausedLabel setFont:[UIFont fontWithName:@"TimesNewRoman" size: 1.0f]]; //change the label's text color pausedLabel.textColor = [UIColor whiteColor]; //add it to your view pausedLabel.transform = CGAffineTransformMakeRotation(89.53); [pausedLabel setHidden: YES]; [self addSubview:pausedLabel]; }
感谢您的帮助!
答案 0 :(得分:2)
你在做:
scoreLabel = [NSString stringWithFormat:@"%d", score];
你应该这样做:
scoreLabel = [[UILabel alloc] init]; // And release it somewhere
scoreString = [NSString stringWithFormat:@"%d", score];
和pauseLabel相同。
答案 1 :(得分:0)
您正在使用NSString类初始化您的标签,它应该是UILabel。确保使用良好的格式化程序生成字符串:%d表示整数,%@表示NSString对象。选中此doc以查找相应的说明符:
NSString* scoreString = [NSString stringWithFormat:@"%d", score];
NSString* anotherString = @"Tap To Resume";
NSString* pausedString = [NSString stringWithFormat:@"%@", anotherString];
答案 2 :(得分:0)
你的第一行是错的。
scoreLabel = [NSString stringWithFormat:@"%d", score];
scoreLabel=[[UILable alloc]init];
scoreLabel.text=[NSString stringWithFormat:@"%i",score];
NextMethod中的相同问题
pausedLabel = [NSString stringWithFormat:@"Tap To Resume"];
这不对
pausedLabel=[[UILable alloc]init];
pausedLable.text=[NSString stringWithFormat:@"Tap To Resume"];
UILable text你正在弄乱的属性,所以它会给你崩溃的问题
答案 3 :(得分:0)
-(void) setupScore{
scoreLabel.text = [NSString stringWithFormat:@"%d", score];
scoreLabel.frame = CGRectMake(262, 250, 100, 40);
[scoreLabel setText:scoreString];
//normally you'll want a transparent background for your label
scoreLabel.backgroundColor = [UIColor clearColor];
//you can use non-standard fonts
[scoreLabel setFont:[UIFont fontWithName:@"TimesNewRoman" size: 1.0f]];
//change the label's text color
scoreLabel.textColor = [UIColor whiteColor];
//add it to your view
scoreLabel.transform = CGAffineTransformMakeRotation(89.53);
[self.view addSubview:scoreLabel];
}
它正常工作我在viewDidLoad中调用它
- (void)viewDidLoad
{ [super viewDidLoad];
scoreLabel=[[UILabel alloc]init];
scoreString=[NSString stringWithString:@"1221"];
score=10;
[self setupScore];
scoreString=[NSString stringWithString:@"11"];
[self setupScore];
scoreString=[NSString stringWithString:@"333"];
[self setupScore];
[self setupScore];
scoreLabel.text=@"okey...";
}