gpt4 book ai didi

iphone - 在 iOS 中以两种不同颜色设置按钮标题

转载 作者:可可西里 更新时间:2023-11-01 04:04:42 26 4
gpt4 key购买 nike

我想为 Button 设置两种颜色的标题。

是否可能与下图相同?

Button in 2 colors

我们将不胜感激。

提前致谢。

最佳答案

这就是你需要的

  UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(5,10,300,20);
[self.view addSubview:btn];

NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"100 Photos"]];
[attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 3)];
[btn setAttributedTitle:attrStr forState:UIControlStateNormal];

关于iphone - 在 iOS 中以两种不同颜色设置按钮标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17340462/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com