github / twui

A framework for developing interfaces on the Mac.
Other
400 stars 79 forks source link

The title of TUIButton won't draw unless "titleLabel" is accessed #46

Closed luosheng closed 12 years ago

luosheng commented 12 years ago

The following code is supposed to create a black button with a red title on it. However it only shows a black rectangle without any text.

TUIButton *button = [[TUIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
[button setTitle:@"Test" forState:TUIControlStateNormal];
[button setTitleColor:[NSColor redColor] forState:TUIControlStateNormal];
[button setBackgroundColor:[NSColor blackColor]];
[self addSubview:button];

It's because the ivar _titleView is only initialized when property titleLabel is accessed in TUIButton.m. But in drawRect:, text values and colors are assigned to a non-initialized ivar _titleView, and [_titleView drawRect:_titleView.bounds] doesn't work as expected since _titleView is nil.

Please change _titleView to self.titleLabel in drawRect:, or at least the first occurrence of _titleView.

dannygreg commented 12 years ago

This issue would be much more valuable as a pull request with the changed code, considering you have identified the problem and also suggested changes.

Could you submit a pull request with the changes?

luosheng commented 12 years ago

OK, I'll do that.