sách gpt4 ai đã đi

ios - 将文本添加到自定义后退按钮 iOS

In lại 作者:行者123 更新时间:2023-11-28 20:23:00 26 4
mua khóa gpt4 Nike

我的导航 Controller 中有一个带图像的后退按钮,我想将文本设置在图像之上。我试过了,但它似乎没有出现:

    UIImage *normalBackImage = [UIImage imageNamed:@"button_tl.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom]; backButton.bounds = CGRectMake(0, 0, normalBackImage.size.width, normalBackImage.size.height );
[backButton setImage:normalBackImage forState:UIControlStateNormal];
backButton.titleLabel.text = @"Back";

有人知道怎么实现吗?谢谢!

1 Câu trả lời

  1. 设置标题的颜色,否则你将看不到任何东西:)

    • setTitleColor:forState:

2。不要尝试设置图像(这意味着 FOREGROUND 图像)。而是设置背景图像 :)

– setBackgroundImage:forState:

Ví dụ:

UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(10, 10, 100, 50);
[backButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[backButton setTitle:@"Bla" forState:UIControlStateNormal];

UIImage *normalBackImage = [UIImage imageNamed:@"button_tl.png"];
[backButton setBackgroundImage:normalBackImage forState:UIControlStateNormal];

[self.view addSubview:backButton];

关于ios - 将文本添加到自定义后退按钮 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15209721/

26 4 0
Bài viết được đề xuất: iphone - 更新自定义 UIView
Bài viết được đề xuất: python - 如何在python程序中添加islice函数?
Bài viết được đề xuất: javascript - 使用 JADE 和 mongoose 对象时出错
Bài viết được đề xuất: python - 装箱(意思)
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com