iphone - 由于 Xcode 中的随机数而更改某些标签的 Alpha 属性

标签 iphone ios xcode4

我需要更改一些标签的 alpha 属性作为随机数生成的结果,我不知道如何识别这些标签以便在代码中调用它们。

例如: 如果生成的数字为 1,则更改包含文本“1”的标签的 alpha 或隐藏属性,依此类推。

我想知道在 xcode 中是否存在类似 javascript 函数 GetElementById() 的东西。

谢谢!

最佳答案

我认为你可以使用标签,你可以试试下面的例子:

UILabel * aLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 160.0f, 30.0f)];
[aLabel setTag:1]; // Set tag here
[aLabel setText:@"1"];
[self.view addSubview:aLabel];
[aLabel release];

UILabel * newLabel = (UILabel *)[self.view viewWithTag:1]; // Get the label here whit tag=1
NSLog(@"%@",newLabel.text); // Print the label text with right tag
[newLabel release];

但标签只能是数字。

关于iphone - 由于 Xcode 中的随机数而更改某些标签的 Alpha 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8093962/

相关文章:

ios - 获取崩溃无法在 ios 中将自己添加为 subview

iphone - 将核心数据的属性的所有值加载到数组中

iphone - 在 UIWebView 中呈现 html 时,iOS 应用程序变得无响应

iphone - 如何使 iPhone 应用程序兼容多个 SDK(固件)版本

iOS 共享扩展不显示/无法接收 URL

ios - 使用转换(_ :to:) method in swift

objective-c - 如何比较objective-c中的字符串对象?

ios - 如何使用 libSystem.B 在 XCode 4 中为 iOS 3.1 部署目标构建?

ios - 如何在 Xcode 4 的 Zombies 工具中找出僵尸 CALayer 属于哪个 UIView?

ios - Xcode 4 - 准备好用于生产了吗?此外,控制台窗口行为