我试图在互联网上找到一些东西,但是现在我没有答案,所以如果你可以帮助我会很棒!到目前为止我有一个NSFont对象,但我想要名称(作为NSString)和字体的大小,所以我可以输出!就像是
[NSFont fontWithName:@"Menlo" size:11];
Run Code Online (Sandbox Code Playgroud)
只有倒退,所以我得到了名字"Menlo"和11号.
感谢帮助!来自德国的Xcoder
我有以下方法做一些字符串构建,但不幸的是我有问题解析布尔值到我的NSString.
代码如下:
- (void)setToolOutput:(int) outputNumber state: (BOOL) value {
NSString *str = [NSString stringWithFormat:@"this=%i is=%c",outputNumber,value];
NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];
[OutputStream write:[data bytes] maxLength:[data length]];
NSLog(@"%@", str);
}
Run Code Online (Sandbox Code Playgroud)
我试图通过使用%cfor char和%s字符串来解析它.两种方式都将我的布尔值输出为a question mark turned upside down.
编辑:我希望它解析为True或False.
可能重复:
使用点或括号语法设置属性是否有区别?
如果我在.h文件中定义一个标签,并且我想在.m文件中更改它的文本,那么使用label.text = @"..."和之间真的有区别[label setText:@"..."]吗?他们似乎做了完全相同的事情,如果是这样,那么为什么不同的方式呢?
为了确保NSString initWithFormat:arguments:按预期返回的格式化字符串是正确的,我需要确定是否有与参数相同数量的格式说明符。下面是一个(稍作和高度编辑的)示例:
- (void)thingsForStuff:(CustomStuff)stuff, ...
{
NSString *format;
switch (stuff)
{
case CustomStuffTwo:
format = @"Two things: %@ and %@";
break;
case CustomStuffThree:
format = @"Three things: %@, %@, and %@";
break;
default:
format = @"Just one thing: %@";
break;
}
va_list args;
va_start(args, method);
// Want to check if format has the same number of %@s as there are args, but not sure how
NSString *formattedStuff = [[NSString alloc] initWithFormat:format arguments:args];
va_end(args);
NSLog(@"Things: %@", formattedStuff);
}
Run Code Online (Sandbox Code Playgroud)
使用这种方法, …
我是iPhone的新手,我想在特殊字符后剪切一个字符串,让我们把这个例子"works.php",我想从这个字符串中删除".php",这意味着我要删除"."之后的内容.这样做的代码是什么?提前致谢.
当不在ARC下时,对于以下代码,
.H
@property (nonatomic, retain) NSString *s;
Run Code Online (Sandbox Code Playgroud)
.M
NSString *m = [NSString stringWithString:@"Hellow, World"];
s = [m retain];
// later on
s = nil; <-- will this release the ref count on the string and hence get the string released?
Run Code Online (Sandbox Code Playgroud) 我drawRect用于文本显示,打电话NSString.我正在尝试使用sizeWithFont默认字体大小为17自动调整字体大小(缩小)并使用循环将字体大小减小1,如果它不适合宽度的大小.任何人都可以帮我解决这个问题吗?现在示例很好我只需要将字体大小设置为17.0
[[self.string displayName] drawAtPoint:CGPointMake(xcoord, ycoord) withFont:[UIFont boldSystemFontOfSize:17.0]];
CGSize size = [[self.patient displayName] sizeWithFont:[UIFont boldSystemFontOfSize:17.0]];
max_current_y = size.height > max_current_y ? size.height : max_current_y;
xcoord = xcoord + 3.0f + size.width;
Run Code Online (Sandbox Code Playgroud) 我想更改NSTextView中特定文本的颜色.该方法应该在keydown事件之后检查.
例如:单词void已完成,字符串void将颜色更改为蓝色.像代码编辑器.
我搜索了很长时间但没有找到任何东西.我的代码:
NSRange range = [text rangeOfString:@"void"];
NSString *substring = [[text substringFromIndex:NSMaxRange(range)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
//I think, here is the mistake.
NSAttributedString *now = [NSAttributedString initWithString:substring];
[now setTextColor:[[NSColor blueColor]]];
Run Code Online (Sandbox Code Playgroud)
我已经读过我必须使用a NSAttributedString但我不知道如何从字符串中获取此类.
我是可可节目中的新手.
谢谢你的帮助!
我正在开发应用程序,我在其中存储NSDictionary中的文件名和文件路径.我的字典就像,
Dict Path : {
background = "file://localhost/var/mobile/Applications/6118A03F-345B-42D5-AC19-25F6D9AC4484/Documents/background.caf";
bgMusic = "file://localhost/var/mobile/Applications/6118A03F-345B-42D5-AC19-25F6D9AC4484/Documents/bgMusic.caf";
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,但当我尝试在JSON字符串中转换字典时,
NSString *strPathForSong = [json stringWithObject:dictPath];
NSLog(@"path sting : %@",strPathForSong);
Run Code Online (Sandbox Code Playgroud)
它返回null字符串.那么有没有办法将带有"/"字符串的字典转换为json字符串?先感谢您
我尝试使用以下代码将NSData转换为十六进制字符串值,但都错了?
这里的"结果"是我的NSdata
我需要一个十六进制字符串作为输出,但我没有得到它
NSUInteger dataLength = [result length];
NSLog(@"%d",dataLength);
NSMutableString *string = [NSMutableString stringWithCapacity:dataLength*2];
const unsigned char *dataBytes = [result bytes];
for (NSInteger idx = 0; idx < dataLength; ++idx) { [string appendFormat:@"%02x", dataBytes[idx]];
}
NSLog(@"%@",string);
Run Code Online (Sandbox Code Playgroud)
我怎么能转换这个请
更新:结果数据包含加密字符串.我想将其转换为十六进制值
nsstring ×10
objective-c ×6
ios ×4
boolean ×1
cocoa ×1
drawrect ×1
hex ×1
ipad ×1
iphone ×1
label ×1
macos ×1
memory-leaks ×1
nsfont ×1
nsfontpanel ×1
nstextview ×1
parsing ×1
sbjson ×1
sizewithfont ×1
uilabel ×1