gpt4 book ai didi

ios - UIscrollview 中的自定义 UIButton

转载 作者:行者123 更新时间:2023-11-28 19:10:59 25 4
gpt4 key购买 nike

我正在使用 xcode 4.6 开发应用程序。在这里,我想以编程方式将 UIButton 添加到 UIscrollview。这是我遵循的代码。

UIButton *bt =[[UIButton alloc]initWithFrame:frame];
bt=[UIButton buttonWithType:UIButtonTypeCustom];
[bt setTitle:@"Custom Button" forState:UIControlStateNormal];
[bt addTarget:self action:@selector(userTappedOnLink:) forControlEvents:UIControlEventTouchUpInside];
bt.backgroundColor = [UIColor grayColor];
bt.titleLabel.textColor=[UIColor blueColor];
[self.mainscrollview addSubview:bt];
[self.mainscrollview bringSubviewToFront:bt];

现在的问题是 Button 在单击时消失了(从技术上讲,它的文本颜色变成了白色)。我检查了将 UIscrollview 颜色保持为红色,即按钮仍在 View 中,但我无法理解其文本颜色发生变化的原因以及如何撤消显示。基本上我想使用 UIbutton 创建一个可点击的链接。我知道 uitextview 方法(datadetectortype),但它没有用,因为我想在链接和实际链接的标签中显示不同的文本。

注意:文本颜色不会变回蓝色,只会保持白色。

提前致谢。

最佳答案

试试下面的代码

UIButton *bt =[UIButton buttonWithType:UIButtonTypeCustom];
bt.frame = CGRectMake(50.0, 50.0, 100.0, 50.0);
[bt setTitle:@"Custom Button" forState:UIControlStateNormal];
[bt addTarget:self action:@selector(userTappedOnLink:) forControlEvents:UIControlEventTouchUpInside];
bt.backgroundColor = [UIColor grayColor];
bt.titleLabel.textColor=[UIColor blueColor];
[self.scrollTest addSubview:bt];

-(void)userTappedOnLink:(UIButton*)sender
{
NSLog(@"Test ..");

[self performSelector:@selector(changeBtnTextColor:) withObject:sender afterDelay:1.0];
}

-(void)changeBtnTextColor:(UIButton*)btn
{
btn.titleLabel.textColor=[UIColor blueColor];
}

希望它对你有用。

关于ios - UIscrollview 中的自定义 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15540275/

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