我有以下代码…
UILabel *buttonLabel = [[UILabel alloc] initWithFrame:targetButton.bounds];
buttonLabel.text = @"Long text string";
[targetButton addSubview:buttonLabel];
[targetButton bringSubviewToFront:buttonLabel];
...这个想法是,我可以有多行文本的按钮,但文本总是被UIButton的backgroundImage掩盖。显示按钮子视图的日志调用显示UILabel已添加,但文本本身无法看到。这是UIButton的bug还是我做错了什么?
在Xcode 9.3中,你可以像下面这样使用storyboard,
你需要设置按钮标题textAlignment到中心
button.titleLabel ?。textAlignment = .center
你不需要像下面这样用新行(\n)设置标题文本,
巴顿。setTitle(“祝\ nAnswer”,为:正常的。)
简单设置标题,
按钮。setTitle(“好答案”,为:.normal)
这是结果,
在Xcode 9.3中,你可以像下面这样使用storyboard,
你需要设置按钮标题textAlignment到中心
button.titleLabel ?。textAlignment = .center
你不需要像下面这样用新行(\n)设置标题文本,
巴顿。setTitle(“祝\ nAnswer”,为:正常的。)
简单设置标题,
按钮。setTitle(“好答案”,为:.normal)
这是结果,