如何将NSButton的图像设置为Finder图标(以编程方式)?
我想在Objective-C/Cocoa(Mac)中这样做
任何帮助,将不胜感激!
当右键单击NSWindow时,有没有办法显示菜单?
我正在尝试将文件保存到路径中,在沙盒应用程序[OS X]中,但到目前为止我几乎每次尝试保存时都会收到错误.错误是......
Error saving: Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “test.txt” in the folder “Testing”." UserInfo=0x1001f5e70 {NSFilePath=/Users/Seb/Desktop/Testing/test.txt, NSUnderlyingError=0x1001f5d70 "The operation couldn’t be completed. Operation not permitted"}
Run Code Online (Sandbox Code Playgroud)
我已将权限的"用户所选文件"设置为"读/写访问权限".
我的代码..
NSString *saveLoc = [NSString stringWithFormat:@"%@/%@.txt",[[NSURL URLWithString:[[NSUserDefaults standardUserDefaults] valueForKey:@"saveURL"]] path],self.theWindow.title];
NSURL *saveURL = [NSURL fileURLWithPath:saveLoc];
NSLog(@"Saving to: %@",saveLoc);
NSError *err = nil;
[self.textView.string writeToURL:saveURL atomically:YES encoding:NSUTF8StringEncoding error:&err];
if (err) {
NSLog(@"Error saving: %@",err);
[[NSAlert alertWithError:err] beginSheetModalForWindow:self.theWindow
modalDelegate:nil
didEndSelector:NULL
contextInfo:nil];
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我该如何保存文件?
谢谢.
我有以下代码:
struct CustomTabView: View where Content: View {
let children: [AnyView]
init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
let m = Mirror(reflecting: content())
if let value = m.descendant("value") {
let tupleMirror = Mirror(reflecting: value)
let tupleElements = tupleMirror.children.map({ AnyView($0.value) }) // ERROR
self.children = tupleElements
} else {
self.children = [AnyView]()
}
}
var body: some View {
ForEach(self.children) { child in
child...
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试将 转换TupleView为数组,AnyView但我收到错误
Protocol type 'Any' …Run Code Online (Sandbox Code Playgroud) 如何设置的图标(家庭和溢出菜单图标)的颜色在Toolbar/ AppBarLayout 编程?
我想更改活动中单个片段的工具栏颜色方案.将AppBarLayout背景设置为浅色(例如浅灰色appBarLayout.setBackgroundResource(..);)会产生白色图标和白色标题,几乎看不到.
其布局如下:
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ToolbarStyle"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)
android material-design android-toolbar android-appbarlayout
有没有办法使NSButton可拖动?我的意思是在最终构建的应用程序中,用户可以拖动NSButton.
我正在尝试做一些几乎"仪表板"式的东西......就像可拖动的东西一样.目前,我只是使用保留在原位的NSButton,但是如果它们可以被拖动它们会很好.
我一直试图在CALayer上显示NSImage.然后我意识到我需要将它显然转换为CGImage,然后显示它......
我有这个代码似乎没有工作
CALayer *layer = [CALayer layer];
NSImage *finderIcon = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kFinderIcon)];
[finderIcon setSize:(NSSize){ 128.0f, 128.0f }];
CGImageSourceRef source;
source = CGImageSourceCreateWithData((CFDataRef)finderIcon, NULL);
CGImageRef finalIcon = CGImageSourceCreateImageAtIndex(source, 0, NULL);
layer.bounds = CGRectMake(128.0f, 128.0f, 4, 4);
layer.position = CGPointMake(128.0f, 128.0f);
layer.contents = finalIcon;
// Insert the layer into the root layer
[mainLayer addSublayer:layer];
Run Code Online (Sandbox Code Playgroud)
为什么?我怎样才能让它发挥作用?
单击按钮时,我希望能够在背景模糊的当前视图(所有配置文件的列表)顶部显示一个视图(带有配置文件信息的圆角矩形)。
以下是我想要达到的目标
这就是我目前拥有的
import SwiftUI
struct profileList: View {
var list: [String]
@State var displayItem: Int = -1
var body: some View {
VStack (spacing: 20){
Text("Profile List").fontWeight(.bold)
.padding(.bottom, 80)
ForEach(0 ..< list.count) {number in
Button(action: {self.displayItem = number}) { Text(self.list[number]) }
}
if (displayItem != -1) {
profileInfo(text: list[self.displayItem])
.padding(.top, -350)
}
Spacer()
}
}
}
struct profileInfo: View {
var text: String
var body: some View {
VStack {
Spacer()
HStack {
VStack(spacing: 20) {
Text(text).fontWeight(.bold).padding(.all, 20)
Text("Name") …Run Code Online (Sandbox Code Playgroud) 如何在窗口打开和关闭时淡出窗口?
这应该可以在Objective C中完成.这必须是AppleScript-Objective-C项目的一部分.我正在使用链接到窗口的属性,并在其上执行makeKeyAndOrderFront ...
任何帮助,将不胜感激!
cocoa ×8
macos ×6
objective-c ×6
swiftui ×2
android ×1
contextmenu ×1
ios ×1
popup ×1
right-click ×1
save ×1
swift ×1
window ×1