NSArray有3个值
@[@"addd:etyrhetwrwr", @"fdfdd:jjjjhhhh", @"fsuy:jjhwgggggg"]
我想用自动换行将这个数组放入UILabel。 因此,当我跑步时,它应该在标签中显示。
addd:etyrhetwrwr
fdfdd:jjjjhhhh
fsuy:jjhwgggggg
但我不能将这个NSArray分开。我怎么能这样做?
答案 0 :(得分:3)
NSArray *myArray = @[@"addd:etyrhetwrwr", @"fdfdd:jjjjhhhh", @"fsuy:jjhwgggggg"];
NSString *labelString = [myArray componentsJoinedByString:@"\n"];
然后使用labelString设置标签text
属性。
答案 1 :(得分:1)
试试这个
NSArray *yourArray = @[@"addd:etyrhetwrwr", @"fdfdd:jjjjhhhh", @"fsuy:jjhwgggggg"];
NSString *string = [myArray componentsJoinedByString:@"\n"];
[yourLabel setText:string];
答案 2 :(得分:0)
您可以通过
分隔UILabel中的NSArray
NSArray myArr = @[@"addd:etyrhetwrwr", @"fdfdd:jjjjhhhh", @"fsuy:jjhwgggggg"];
NSString strLabel = [myArr string:@"\n"];
答案 3 :(得分:0)
试试这段代码
NSArray *array = [[NSArray alloc] initWithObjects:@"adad",@"fgfdgdfg",@"sddgfs", nil];
NSMutableString *strFinalData = [[NSMutableString alloc] init];
for (int i=0; i<[array count]; i++)
{
[strFinalData appendFormat:@"%@ ",[array objectAtIndex:i]];
}
NSLog(@"Final String: %@",strFinalData);
现在设置yourLabel.text = strFinalData;