我正在用一个带有图像集的三个NSButton做一个小应用程序.这些按钮没有边框也没有背景.但是,当我单击一个按钮时,它变成一个灰色矩形.
我怎样才能解决这个问题?谢谢.
在OSX上我有一个非常暗的图像的NSButton,不幸的是,使用属性检查器无法更改颜色.看图片大黑色按钮,文字是Go.

是否有可能改变文字颜色的线索?我查看了NSButton类,但没有方法可以做到这一点.我知道我可以使用白色字体制作图像,但这不是我想要做的.
来自瑞士的问候,罗纳德霍夫曼---
我正在NSButtonCell为自定义渲染创建自定义.
现在,我希望有不同的方面取决于鼠标是否在按钮上方.我怎样才能获得这些信息?
感谢致敬,
我有一个NSButton(按钮),在Interface Builder/Xcode中内置了一些临时标题文本.在其他地方,按钮内的标题文本以编程方式更改为未知长度的字符串(实际上,多次到许多不同的长度).
我希望按钮能够自动调整大小(具有固定的右侧位置 - 因此它向左延伸)以适合以编程方式插入的任何长度的字符串作为按钮文本.但我无法弄明白.有什么建议?提前致谢!
如果未启用NSButton,则mouseDown:和mouseUp:按预期运行(因此,当按下鼠标时,将调用mouseDown:,当它被释放时,将调用mouseUp:)
但是,如果启用了NSButton IS,则完全不会调用mouseUp:并且在鼠标释放后调用mouseDown:
- (void)mouseDown:(NSEvent *)theEvent {
[super mouseDown:theEvent];
}
- (void)mouseUp:(NSEvent *)theEvent {
[super mouseUp:theEvent];
}
Run Code Online (Sandbox Code Playgroud)
为什么这种行为有所不同,我如何强制执行正确的行为(与未启用按钮时相同)
我正在快速学习.我想知道如果按下一个按钮,如何以编程方式调用一个函数....我试过这个,但是当程序启动时直接执行该功能,而不是当我按下按钮时......你能不能帮助我修复这个..谢谢你下面这个测试应用程序的完整ViewController.swift
//
// ViewController.swift
// hjkhjkjh
//
// Created by iznogoud on 14/05/16.
// Copyright © 2016 iznogoud. All rights reserved.
//
import Cocoa
class ViewController: NSViewController {
func printSomething() {
print("Hello")
}
override func viewDidLoad() {
super.viewDidLoad()
let myButtonRect = CGRect(x: 10, y: 10, width: 100, height: 10)
let myButton = NSButton(frame: myButtonRect)
view.addSubview(myButton)
myButton.target = self
myButton.action = Selector(printSomething())
// Do any additional setup after loading the view.
}
override var representedObject: AnyObject? {
didSet {
// Update …Run Code Online (Sandbox Code Playgroud) 使用代码(不是"接口"构建器)我需要创建一个NSButton看起来像图像的东西.具体来说,我想用NSImageNameStopProgressFreestandingTemplate我需要它不是看起来像按钮,但看起来像图像.这意味着:
1.没有"按下按钮"外观
2.没有边框,按钮没有任何可见性
谢谢.
我是可可的新手.我的应用程序中有一个按钮和一个textField.我想在textfield为空时禁用该按钮,并在用户输入内容时启用.
有什么要开始的吗?Interface Builder中的任何"魔术"绑定?
谢谢
[EDITED]
我试图将appDelegate设置为NSTextfield的委托并添加了此方法(myTextfield和myButton是IBOutlets):
- (void)textDidChange:(NSNotification *)aNotification
{
if ([[myTextField stringValue]length]>0) {
[myButton setEnabled: YES];
}
else {
[myButton setEnabled: NO];
}
}
Run Code Online (Sandbox Code Playgroud)
但没有任何反应......
在我的应用程序中,我更改standardWindowButtons close/miniturize/expand的位置,如下所示:
//Create the buttons
NSButton *minitButton = [NSWindow standardWindowButton:NSWindowMiniaturizeButton forStyleMask:window.styleMask];
NSButton *closeButton = [NSWindow standardWindowButton:NSWindowCloseButton forStyleMask:window.styleMask];
NSButton *fullScreenButton = [NSWindow standardWindowButton:NSWindowZoomButton forStyleMask:window.styleMask];
//set their location
[closeButton setFrame:CGRectMake(7+70, window.frame.size.height - 22 - 52, closeButton.frame.size.width, closeButton.frame.size.height)];
[fullScreenButton setFrame:CGRectMake(47+70, window.frame.size.height - 22 -52, fullScreenButton.frame.size.width, fullScreenButton.frame.size.height)];
[minitButton setFrame:CGRectMake(27+70, window.frame.size.height - 22 - 52, minitButton.frame.size.width, minitButton.frame.size.height)];
//add them to the window
[window.contentView addSubview:closeButton];
[window.contentView addSubview:fullScreenButton];
[window.contentView addSubview:minitButton];
Run Code Online (Sandbox Code Playgroud)
现在当窗口出现时带有按钮有两个问题:1.它们是灰色而不是正确的颜色2.当鼠标悬停在它们上面时,它们不显示+ - 或x符号
任何人都可以告诉我我做错了什么.谢谢.
nsbutton ×10
cocoa ×7
macos ×4
objective-c ×2
appkit ×1
cursor ×1
ios ×1
nsbuttoncell ×1
nscontrol ×1
nsimage ×1
nstableview ×1
nstextfield ×1
nsview ×1
nswindow ×1
selector ×1
swift ×1
textcolor ×1
xcode ×1