转义@“" "目标C中的字符 [英] Escaping the @" " characters in Objective C

查看:86
本文介绍了转义@“" "目标C中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试基于传递的"artistID"设置视图的背景图像.到目前为止,这是我的代码:

I'm trying to set the background image of a view based on a passed "artistID." Here is my code so far:

 NSString *backgroundImageName = [[NSString alloc]initWithFormat:@"artistbackground%i.png",_artistID];


    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:backgroundImageName]];
    NSLog(@"%@",backgroundImageName);

不幸的是,对于ImageNamed中的参数,我传入了: artistibackground1

unfortunately, for the parameter in ImageNamed, I'm passing in: artistibackground1

代替:

@"artistbackgound1"

@"artistbackgound1"

关于如何转义@和引号的任何想法?

Any ideas on how to escape the @ and the quotes??

谢谢!

推荐答案

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:[NSString stringWithFormat:@"@%@",backgroundImageName]];

本质上是两个字符串,它将在第二个字符串中添加@".

Essentially make two strings, it will add the @"" in the second.

这篇关于转义@“" "目标C中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆