gpt4 book ai didi

ios - 更改按钮标签

转载 作者:行者123 更新时间:2023-11-28 18:23:25 24 4
gpt4 key购买 nike

我是 iOS 应用开发的新手。目前我正在开发一个非常简单的应用程序,它在屏幕上显示两个词,用户选择一个词,应用程序只输出你选择了 x。

我创建了两个 plist,并将它们加载到一个数组中并在数组中随机化。在我看来,我有两个按钮,我希望在它们上面显示文字。但是,我有两个问题..1.我希望按钮上的标签在应用程序启动时发生变化。所以用户不必点击按钮或任何东西。2. 我希望 array_1 中的一个随机单词(从 plist 加载)出现在随机按钮上。 button_1 或 button_2 和列表 array_2 相同。

这是我到目前为止所做的。 (在论坛的帮助下 (:)

- (IBAction)buttonpressed:(id)sender {

// Load contents of plist onto array

NSString *path = [[NSBundle mainBundle] pathForResource:@"wordsOne" ofType:@"plist"];
NSMutableArray *words = [NSMutableArray arrayWithContentsOfFile:path];

//shuffle them using Fisher–Yates shuffle algorithm

for (int i = words.count-1; i>=0; i--) {
int r = arc4random_uniform(words.count);
[words exchangeObjectAtIndex:i withObjectAtIndex:r];
}

// assign word to the button
for (int j =0; j<_WordButton.count; j++) {
UIButton *button = [_WordButton objectAtIndex:j];
button.titleLabel.text = [words objectAtIndex:j];
}

}

上面的代码有明显的缺陷,比如它只使用了一个plist,并没有在两个按钮上随机显示单词。

最佳答案

您可以使用以下代码设置 UIButton 标题:

[button setTitle:titleString forState:UIControlStateNormal];

关于ios - 更改按钮标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16118617/

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