Jos*_*osa 3 cocoa cocoa-touch objective-c ios
基本上,我有一个分享按钮,可以提取撰写电子邮件模式视图.我想在我的NSStringWithFormat中添加一个制表空间.让我们称之为"postText".当我尝试设置这样的空间时:
NSString *postText = [NSString stringWithFormat:@"\tHello, World! %@",myPointer];
它没有插入任何东西(它返回"Hello,World!myPointerValue"),如果我只是使用tab,它会混乱间距,因为我需要使用tab大约10-20次.难道我做错了什么?
Jan*_*mal 12
您可以使用stringByPaddingToLength
函数在字符串中的任何位置添加空格.检查以下样本功能.
-(NSString*)stringByAddingSpace:(NSString*)stringToAddSpace spaceCount:(NSInteger)spaceCount atIndex:(NSInteger)index{
NSString *result = [NSString stringWithFormat:@"%@%@",[@" " stringByPaddingToLength:spaceCount withString:@" " startingAtIndex:0],stringToAddSpace];
return result;
}
Run Code Online (Sandbox Code Playgroud)
您的案例中的示例用法:
NSString *spaceAddedText = [self stringByAddingSpace:@"Hello World!" spaceCount:5 atIndex:0]
NSString *postText = [NSString stringWithFormat:@"%@%@",spaceAddedText,myPointer];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4897 次 |
最近记录: |