Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 一个标签中有多个字符串_Objective C_String_Uilabel - Fatal编程技术网

Objective c 一个标签中有多个字符串

Objective c 一个标签中有多个字符串,objective-c,string,uilabel,Objective C,String,Uilabel,我有一个需要显示两个字符串的标签。目前,我有以下几点: self.artistLabel.text = self.string1; 我希望能够显示字符串1和字符串2。如果可能,我还需要在两个字符串之间有一个“@”符号。我知道这一定很简单,我就是想不出来。你可以这样做: self.artistLabel.text = [NSString stringWithFormat:@"%@ %@" , self.string1 , self.string2 ]; 一个UILab

我有一个需要显示两个字符串的标签。目前,我有以下几点:

     self.artistLabel.text = self.string1;

我希望能够显示字符串1和字符串2。如果可能,我还需要在两个字符串之间有一个“@”符号。我知道这一定很简单,我就是想不出来。

你可以这样做:

self.artistLabel.text = [NSString
    stringWithFormat:@"%@ %@"
,   self.string1
,   self.string2
];

一个UILabel中只能显示一个字符串。但是,该字符串本身可以是多个字符串的组合

要组合字符串,请查看类似
stringByAppendingString:
的方法

//Create a new string from both string1 and string2 with an "@" in the middle
NSString *artistLabelString = [NSString stringWithFormat:"%@@@%@", self.string1, self.string2];

//Set the label
self.artistLabel.text = artistLabelString;

就像BTW,中间的<代码> @ @ /代码>给你一个单一的代码> @ /代码>。< /P>这是完美的,干杯。我还在两个字符串之间添加了“@”,只需使用:

stringWithFormat:@“%@%@”
@user3429966如果使用单个@并使用xcode,您应该会收到警告。@MiloGosnell不,您不会的。字符串格式的
@
符号没有什么特别之处,除非它前面有
%
符号。现在一个
%
是坏的。如果您希望字符串中有一个实际的
%%
,它必须是
%%
。谢谢,这个方法也很棒。这是错误的。您只需要一个
@
就可以在字符串中获得实际的
@