我從NSMutableArray
動態創建標籤。在創建標籤時,我爲每個標籤設置了標籤。我有一個NSMutableArray
名爲wordArray
。現在,我想檢查我的字符串是wordArray或不可用, 我可以檢查這個使用:如何在iPhone中獲取UILabel標籤
[wordArray containsObject:wordStr];
用於動態創建標籤:
UILabel *wordLabl;
int tagValue3 = 1;
for (int iloop = 0; iloop < [wordArray count]; iloop++)
{
wordLabl = [self addwordLabelRect:CGRectMake(80 * iloop + 20, 420 , 100, 20)andTag:tagValue3];//30 + 35 30 * iloop+
[self.view addSubview:wordLabl];
tagValue3 += 1;
}
-(UILabel *)addwordLabelRect:(CGRect)rect andTag:(int)integerValue
{
wordLabel = [[UILabel alloc] init];
wordLabel.frame = rect;
wordLabel.userInteractionEnabled = YES;
wordLabel.tag = integerValue;
wordLabel.backgroundColor = [UIColor clearColor];
wordLabel.font = [UIFont systemFontOfSize:15];
wordLabel.text = [NSString stringWithFormat:@"%@",[wordArray objectAtIndex:integerValue - 1]];
wordLabel.textAlignment = NSTextAlignmentCenter;
wordLabel.textColor = [UIColor whiteColor];
return wordLabel;
}
使用上面的代碼中,我創建標籤和標籤。 但是,如果wordArray
包含字符串我想要更改該標籤的textColor
.I認爲這可以使用標籤來完成,但我怎樣才能獲得標籤的標籤值。
你可以做的是存儲這些標籤在數組中標記,然後根據該標籤獲取標籤。你可以輕鬆地做到我的朋友.... – NiravPatel
你是否在'NSMutableArray'中存儲了創建的'UILabels'?顯示您的代碼 –
如果您提供代碼,將有助於提供精確的解決方案 –