说我有一个句子呈现That looks like this
。
如果我想要在like
上说更多的空间,我该怎么做?所以它实际上看起来像That looks like this.
注入空格不起作用。
在迅速使用\u{2000}
。 (可能\u2000
在Objective-C)。
请尝试这样
1.选项
NSString *str = [NSString stringWithFormat:@"That looks %4s this",[@"like" UTF8String]];
%@ formatter不会添加空格来调整字段宽度。所以我使用带有%s说明符的UTF8String来调整宽度。
宽度指定要输出的最小字符数,通常用于填充表格输出中的固定宽度字段
第二选择
在字符串中添加制表符空间
NSString *string = @"That looks \t like this";
希望它会奏效。
试试这个
NSString *string = @"That looks \u00a0 \u00a0 like this";
要使用属性执行此操作,请将空格所在范围内的字体设置为大于字符串其余部分的字体。 (比例字体大得多)
NSString *string = @"That looks like this";
NSMutableAttributedString *attrString=[[NSMutableAttributedString alloc] initWithString:string];
[attrString addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:50.0] // big
range:NSMakeRange(4, 1)];
[attrString addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:50.0]
range:NSMakeRange(10, 1)];
// present it somewhere where attributes are rendered
self.textView.attributedText = attrString;
你也可以
[yourString stringByReplacingOccurrencesOfString:@"like" withString:@" like "];