简体   繁体   English

如何设置标题

[英]how to set title

NSString *formatString = NSLocalizedString(@"%1$i of %2$i", @"Picture X out of Y total.");
NSString *countTitle = [NSString stringWithFormat:formatString, currentIndex_ + 1, photoCount_,  nil];
[self setTitle:countTitle];

in this code the title showing Ex." 22 of 44" that means 22nd photos out of 44 i want add title like "album name + countTitle" which is above in the code so that wil become like and i want to give the name of album is "Flickr" 在此代码中,标题显示示例“ 44中的22”,这表示44中的22张照片,我想在代码中添加标题,例如“相册名称+ countTitle”,该名称位于代码上方,以便变得像这样,我想给出名称专辑是“ Flickr”

Ex. 例如 "Flickr 22 of 44" how the code will be “ Flickr 22 of 44”代码将如何

That is pretty simple, you just need to add an extra format string modifier and add the variable in the correct place in your stringWithFormat: like so (where albumName is the name of your album`): 这很简单,您只需要添加一个额外的格式字符串修饰符,然后将变量添加到stringWithFormat:的正确位置即可,就像这样(其中albumName是您的相册的名称):

NSString *formatString = NSLocalizedString(@"%@ %1$i of %2$i", @"Picture X out of Y total.");
NSString *countTitle = [NSString stringWithFormat:formatString, albumName, currentIndex_ + 1, photoCount_,  nil];
[self setTitle:countTitle];

Also just to note, instead of using %1$i and %1$i for integers, you can just use %d for C Integers in your format string like so: 还要注意,不使用%1$i%1$i作为整数,而可以将%d用于格式字符串中的C Integer,如下所示:

NSString *formatString = NSLocalizedString(@"%@ %d of %d", @"Picture X out of Y total.");
NSString *countTitle = [NSString stringWithFormat:formatString, albumName, currentIndex_ + 1, photoCount_,  nil];
[self setTitle:countTitle];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM