嗨,我对 titleLabel 属性有疑问。当我想改变它。变化没有出现。这是我的代码:
UIButton *menuItemButton = [[UIButton alloc] initWithFrame:CGRectMake(x, y, 290.0, 35.0)];
[menuItemButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[menuItemButton setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
menuItemButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[menuItemButton setContentEdgeInsets:UIEdgeInsetsMake(0, 11.0, 0, 0)];
[menuItemButton setTitle:(NSString *)[itemParams objectForKey:@"Name"] forState:UIControlStateNormal];
[menuItemButton setBackgroundImage:menuItemImage forState:UIControlStateNormal];
[menuItemButton setTag:idx];
[[menuItemButton titleLabel] setFont:[UIFont fontWithName:@"Vardana" size:5]];
[menuItemButton addTarget:self action:@selector(menuItemClicked:) forControlEvents:UIControlEventTouchUpInside];
这不起作用:
[[menuItemButton titleLabel] setFont:[UIFont fontWithName:@"Vardana" size:15]];
我也在尝试:
[menuItemButton.titleLabel setFont:[UIFont fontWithName:@"Vardana" size:15]];
menuItemButton.titleLabel.font = [UIFont fontWithName:@"Vardana" size:15];
titleLabel 的其他属性也不适用于 ex。对齐和颜色。
我要写的所有viewDidLoad
东西[super viewDidLoad];