8
有關此UIButton的所有內容都呈現出很好的效果,除了應該放在其上的文字。 NSLog證明文本處於正確的位置。是什麼賦予了?爲什麼這個UIButton不顯示它的文本標籤?
UIButton *newTagButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[newTagButton addTarget:self action:@selector(showNewTagField) forControlEvents:UIControlEventTouchUpInside];
newTagButton.titleLabel.text = @"+ New Tag";
NSLog(@"Just set button label to %@", newTagButton.titleLabel.text);
newTagButton.titleLabel.font = [UIFont systemFontOfSize:17];
newTagButton.titleLabel.textColor = [UIColor redColor];
CGSize addtextsize = [newTagButton.titleLabel.text sizeWithFont:[UIFont systemFontOfSize:17]];
CGSize buttonsize = { (addtextsize.width + 20), (addtextsize.height * 1.2) };
newTagButton.frame = CGRectMake(x, y, buttonsize.width, buttonsize.height);
[self.mainView addSubview:newTagButton];
賓果。謝謝! – 2010-06-11 18:14:31