gpt4 book ai didi

objective-c - cocoa :如何让图标一直靠右?

转载 作者:行者123 更新时间:2023-12-03 17:58:15 25 4
gpt4 key购买 nike

这个窗口的状态栏。如何让图标一直靠右呢?调整窗口大小,它会自动向右移动。

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];
}

最佳答案

如果您希望您的图标右对齐,您需要将其自动调整大小更改为右对齐。您需要在尺寸检查器中这样做:

Size Inspector

或者只是使用-setAutoresizingMask,如下所示:

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


此外,您的 newFrame 的 x 位置设置为 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);

关于objective-c - cocoa :如何让图标一直靠右?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10265396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com