将标题设置为状态项目可可的自定义视图

时间:2019-06-14 13:59:04

标签: objective-c macos statusbar nsstatusitem

我有自定义状态视图,该视图已设置为状态项视图属性。

componentDidMount() {
    $(document).ready(function(){
        $('form#registerForm').keyup(async function() {
        if ($('input[name="postcode"]').val().length >= 4 && $('input[name="huisnummer"]').val().length >= 1) {
            const postcode = $('input[name="postcode"]').val();
            const huisnummer = $('input[name="huisnummer"]').val();
            $.ajax({
            url: `http://localhost:5000/subscription/addressLookup?postalcode=${postcode}&housenumber=${huisnummer}&housenumberext=`,
            type: "get", //send it through get method
            success: (response)=> {
               this.setState({register_straatnaam:response.street})
            },
            error: function(xhr) {
                console.log(xhr)
            }
            });
        }
        });
    });
}

我在启动时初始化了状态栏,并在状态项中显示了该图标。 收到通知- (id)initWithStatusItem:(NSStatusItem *)statusItem { CGFloat itemWidth = [statusItem length]; CGFloat itemHeight = [[NSStatusBar systemStatusBar] thickness]; NSRect itemRect = NSMakeRect(0.0, 0.0, itemWidth, itemHeight); self = [super initWithFrame:itemRect]; //isReachable = YES; if (self != nil) { _statusItem = statusItem; _statusItem.view = self; [self checkReachability]; } return self; } - (void)drawRect:(NSRect)dirtyRect { NSColor *tintColor = [NSColor blackColor]; tintColor = (!_isReachable)?[NSColor grayColor]:(self.isHighlighted?[NSColor whiteColor]:([self isDarkStyle]?[NSColor whiteColor]:[NSColor blackColor])); self.image = [[NSImage imageNamed:@"icn_statusitem"] imageTintedWithColor:tintColor]; [self.statusItem drawStatusBarBackgroundInRect:dirtyRect withHighlight:self.isHighlighted]; NSImage *icon = self.image; NSSize iconSize = [icon size]; NSRect bounds = self.bounds; CGFloat iconX = roundf((NSWidth(bounds) - iconSize.width) / 2); CGFloat iconY = roundf((NSHeight(bounds) - iconSize.height) / 2); NSPoint iconPoint = NSMakePoint(iconX, iconY); [icon drawAtPoint:iconPoint fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; //[self checkReachability]; } 后,我想将状态项图像更改为字符串。  我已经试过了,这不起作用

statusSpeedNotification

任何建议都会更有帮助。

0 个答案:

没有答案