相关疑难解决方法(0)

iOS:UIButton titleLabel - 它做了什么吗?

我想制作一个类型为UIButtonTypeCustom的UIButton(用于形状).我想使用button.titleLabel分配标题,因为我需要指定字体.以下代码看起来应该可以工作,但不会 - 没有标签显示,句点.

UIImage *editButtonImage = [UIImage imageNamed: @"editButton.png"];
float width = editButtonImage.size.width;
float height = editButtonImage.size.height;

UIButton *editButton = [UIButton buttonWithType: UIButtonTypeCustom];
editButton.frame = CGRectMake(0, 0, width, height);
[editButton setBackgroundImage: editButtonImage forState: UIControlStateNormal];
editButton.adjustsImageWhenHighlighted = YES;
editButton.titleLabel.text = @"Edit";
editButton.titleLabel.textColor = [UIColor whiteColor];
editButton.titleLabel.textAlignment = UITextAlignmentCenter;
editButton.titleLabel.font = [UIFont fontWithName: @"Helvetica" size: 14];
[self.view addSubview: editButton];
Run Code Online (Sandbox Code Playgroud)

每个人总是说使用setTitle:forState:但是这会给你一个我不喜欢的字体.不推荐使用titleLabel方法 - 它应该可以工作.

我之前已经遇到过好几次并且总是只是解决它,但我真的想弄明白.有任何想法吗?

iphone uibutton uilabel uifont ios

27
推荐指数
1
解决办法
4万
查看次数

标签 统计

ios ×1

iphone ×1

uibutton ×1

uifont ×1

uilabel ×1