0

this window status bar.How to make the icon has been relying on the right ? Resize the window , it automatically to the right .

enter image description here

-(void)composeInterface{
    NSView *themeFrame=[[self.window contentView] superview];
    NSRect themeFrameRect = [themeFrame frame];
    NSRect accessoryViewFrame =[self.statusBarBtn frame];
    NSRect newFrame = NSMakeRect(30,
                                 themeFrameRect.size.height - accessoryViewFrame.size.height,
                                 accessoryViewFrame.size.width,
                                 accessoryViewFrame.size.height);

    [self.statusBarBtn setFrame:newFrame];
//    [self.statusBarBtn setFrameOrigin:NSMakePoint(0, 0)];
//    [self.statusBarBtn setAutoresizingMask:323];

    [themeFrame addSubview:self.statusBarBtn];
}
4

1 回答 1

1

如果您希望您的图标右对齐,您需要更改它的自动调整大小以右对齐。您需要在Size Inspector中这样做:

尺寸检查器

或者-setAutoresizingMask像这样使用:

[self.statusBarBtn setAutoresizingMask:333]; //NOT 323


此外,您newFrame的 'sx 位置设置为 30,因此图标将位于左侧。

改变这个:

NSRect newFrame = NSMakeRect(30,
                             themeFrameRect.size.height - accessoryViewFrame.size.height,
                             accessoryViewFrame.size.width,
                             accessoryViewFrame.size.height);

对此:

NSRect newFrame = NSMakeRect(themeFrameRect.size.width - accessoryViewFrame.size.width,
                             themeFrameRect.size.height - accessoryViewFrame.size.height,
                             accessoryViewFrame.size.width,
                             accessoryViewFrame.size.height);
于 2012-04-22T06:22:21.760 回答