- (voID) getScreenResolution { NSArray *screenArray = [NSScreen screens]; NSScreen *mainScreen = [NSScreen mainScreen]; unsigned screenCount = [screenArray count]; unsigned index = 0; for (index; index < screenCount; index++) { NSScreen *screen = [screenArray objectAtIndex: index]; NSRect screenRect = [screen visibleFrame]; Nsstring *mString = ((mainScreen == screen) ? @"Main" : @"not-main"); NSLog(@"Screen #%d (%@) Frame: %@",index,mString,NsstringFromrect(screenRect)); }}
输出:
Screen #0 (Main) Frame: {{0,4},{1344,814}}
有没有办法格式化{1344,814}到1344×814?
编辑:
这完美工作:
- (Nsstring*) screenResolution { NSRect screenRect; NSArray *screenArray = [NSScreen screens]; unsigned screenCount = [screenArray count]; unsigned index = 0; for (index; index < screenCount; index++) { NSScreen *screen = [screenArray objectAtIndex: index]; screenRect = [screen visibleFrame]; } return [Nsstring stringWithFormat:@"%.1fx%.1f",screenRect.size.wIDth,screenRect.size.height];}解决方法 NSLog(@“%fx%f”,screenRect.size.wIDth,screenRect.size.height); 总结
以上是内存溢出为你收集整理的可可 – 在Mac OS X中以编程方式获取屏幕大小全部内容,希望文章能够帮你解决可可 – 在Mac OS X中以编程方式获取屏幕大小所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)