在目标C中转义@“”字符
我试图根据传递的“artistID”来设置视图的背景图像。 这是我的代码到目前为止:
NSString *backgroundImageName = [[NSString alloc]initWithFormat:@"artistbackground%i.png",_artistID]; self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:backgroundImageName]]; NSLog(@"%@",backgroundImageName);
不幸的是,对于ImageNamed中的参数,我传入:artistibackground1
代替:
@ “artistbackgound1”
任何想法如何逃脱@和引号
谢谢!!
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:[NSString stringWithFormat:@"@%@",backgroundImageName]];
基本上做两个string,它会在第二个添加@“”。
你应该在你想要的angular色之前使用\。 一个例子:
NSLog(@"\@\"Try\"");
代码打印
@"Try"
不要忘记,甚至string常量也是Objective-C中的NSString对象。 这是魔法的一部分! 我经常看到写这行文字的新手程序员:
[NSString stringWithFormat:@"@%@",backgroundImageName];
但是你可以简化这一行:
[@"@" stringByAppendingString:backgroundImageName];
魔法!
- Firebase iOS无法获取默认标记Error Domain = com.firebase.iid Code = 6“(null)”
- 编码和解码3D MPO文件Objective-C
- iOS 8 – 获取当前date为DD / MM / YYYY
- 在iOS11的tableHeaderView中使用UISearchController和UISearchBar
- iOS xcode4 AVQueuePlayer不能播放声音
- Swift:在PAT上实现动态调度(具有关联类型的协议)
- 有没有办法自定义UISearchDisplayController单元格
- Xcode免费供应:“Apple推送通知”function仅适用于在Apple开发者计划中注册的用户
- 隐藏另一个button时居中一个button的约束