小编Gür*_*LAK的帖子

NSMenuItem中的自定义视图未正确突出显示

我尝试使用自定义视图NSMenuitem,这是有效的.不幸的是,我在突出显示方面遇到了一些困难(鼠标悬停).我已经按照其他线程中的说明在drawRect:我的NSView子类中实现手动执行蓝色突出显示.这似乎有效,但突出显示颜色不正确.与普通菜单项相比,它看起来太暗了,有趣的subviews是我的自定义视图使用了正确的高亮颜色(见截图).有关如何解决此问题的任何想法?

drawRect:NSView子类中的当前方法如下所示:

- (void)drawRect:(NSRect)dirtyRect
{
    [super drawRect:dirtyRect];

    BOOL isHighlighted = [[self enclosingMenuItem] isHighlighted];
    if (isHighlighted)
    {
        [[NSColor selectedMenuItemColor] setFill];
        NSRectFill(dirtyRect);

        [self.profileNameView setTextColor:[NSColor whiteColor]];
        [self.securedIPView setTextColor:[NSColor whiteColor]];
        [self.separatorView setTextColor:[NSColor whiteColor]];
        [self.connectionTimeView setTextColor:[NSColor whiteColor]];
    }
    else
    {
        [self.profileNameView setTextColor:[NSColor controlTextColor]];
        [self.securedIPView setTextColor:[NSColor disabledControlTextColor]];
        [self.separatorView setTextColor:[NSColor disabledControlTextColor]];
        [self.connectionTimeView setTextColor:[NSColor disabledControlTextColor]];
    }
}
Run Code Online (Sandbox Code Playgroud)

结果突出显示如下:

在此输入图像描述

cocoa objective-c nsview nsmenuitem

6
推荐指数
0
解决办法
737
查看次数

使用UIImage全屏时需要哪些类型/尺寸的图像?

我的目标是iOS8发布应用程序.所以它将在4S,5,6,6 +和iPad 2+上提供.

我有一个ViewController地方,我提出的UIImageView是我UIViewController视图的整个大小.

我的问题是......我需要什么尺寸的图像.我是否需要为每个设备提供特殊尺寸的尺寸?或者4s/5/6是否都使用相同的比例,而6+有自己独特的比例?或者我只使用1个图像大小并让它自动缩放(或者拉伸/倾斜图像)?

此外,图像的最小尺寸是多少?例如,如果它小于iPhone 6+的原生尺寸,图像质量是否会下降?

cocoa-touch objective-c uiimageview ios

6
推荐指数
1
解决办法
329
查看次数

在 xcode 项目中的目标之间共享数据

我有一个项目有两个不同的目标(同一个应用程序的免费和付费版本),我有一个list项目,我保存到NSUserDefaults. 我的问题是,有没有办法在两个版本的应用程序之间共享这个列表,而不使用KeyChain或类似的东西?

objective-c ios

4
推荐指数
1
解决办法
1437
查看次数

下载的文件不存在

我使用本教程在后台下载文件

下载文件时,有2个功能通知我们.我按时间顺序写下它们:

1) - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)downloadURL;

2) - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error;

在功能1中,我检查下载的文件是否仍然存在.

在功能2中,我检查下载的文件是否存在.我认为它被iOS系统删除了.

你能解释一下为什么吗?谢谢

objective-c ios

3
推荐指数
1
解决办法
2201
查看次数

在后台线程加载UI好吗?

我的应用程序目前由a TableViewController和a组成ViewController.当选中a cellTableView,ViewController会推送,这是主应用程序.此视图控制器先前将其全部加载UIViews主线程中,这导致屏幕在代码运行时冻结,通常会导致用户认为它已崩溃.为了防止出现此问题并改善用户体验,我将代码更改为以下整体格式:

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

[self initialiseApp];

}

- (void) initialiseApp {

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    //Initialising views

    imageView = [[UIImageView alloc] initWithImage:[self getImageFromUrl:currentWallpaperURL]];
    [imageView setFrame:CGRectMake(0.0, 100, screenWidth, (screenWidth/7)*4)];
    [imageView setContentMode:UIViewContentModeScaleAspectFit];

// etc etc for other views

    dispatch_async(dispatch_get_main_queue(), ^{
        //Add subviews to UI

        [[self view] addSubview:imageView];
    });
});

}
Run Code Online (Sandbox Code Playgroud)

当应用程序在模拟器中运行时,这会导致ViewController加载为空白屏幕,稍后加载UI一段时间后.在加载过程中,我会在屏幕上显示某种形式的微调器或文本.因此,我想澄清一下这个主题:

正在加载应用程序UI时 …

multithreading objective-c uiviewcontroller ios

2
推荐指数
1
解决办法
814
查看次数

NSArray 分配和初始化

我对初始化有点困惑NSArray。令人困惑的是,我们有不同的init方法来初始化它,如果我只是初始化它而不给出任何大小和任何对象,编译器如何知道RAM. init 方法背后的逻辑/差异是什么?有人可以简单解释一下吗?

编辑:

NSArray *sortedArray = [[NSArray alloc] init];
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc]   initWithKey:@"quota" ascending:NO];
NSArray *sortDescriptors = [NSArray arrayWithObject:descriptor];
//How is that possible to modifying to immutable object
sortedArray = [sortedContainers sortedArrayUsingDescriptors:sortDescriptors];
Run Code Online (Sandbox Code Playgroud)

我知道NSArrayNSMutableArray之间的差异,并且我不是在寻找差异。我只是想知道该代码如何编译/执行而不会出现错误。

objective-c nsarray ios

0
推荐指数
1
解决办法
4002
查看次数