OGeek|极客世界-中国程序员成长平台

标题: ios - 以编程方式创建 UIButton,但没有点击效果(仅限文本效果) [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 10:19
标题: ios - 以编程方式创建 UIButton,但没有点击效果(仅限文本效果)

我创建了一个这样的按钮,但是当我点击它时没有任何变化。

    UIButton *button = [[UIButton alloc] init];
    button.translatesAutoresizingMaskIntoConstraints = NO;
    [button setTitle: @"xxxxx" forState: UIControlStateNormal];
    [button setTitleColor: [UIColor colorWithRed:0.98 green:0.44 blue:0.05 alpha:1] forState: UIControlStateNormal];

我不会使用两张图片,我只是想让文字稍微改变一下。就像一个新的按钮被拖到 UIViewController。

我错过了什么?



Best Answer-推荐答案


点击按钮时必须设置标题和标题颜色。

 [button setTitle: @"clicked" forState: UIControlStateHighlighted];
 [button setTitleColor: [UIColor redColor] forState: UIControlStateHighlighted];

UIControl Class Reference

关于ios - 以编程方式创建 UIButton,但没有点击效果(仅限文本效果),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28659700/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4