- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在努力将我的自定义样式 ( example ) 应用到我正在构建的 OSX 桌面应用程序中,我想知道执行此操作的范例/习惯用法是什么。
NSTextField
、NSButton
和 NSPopUpButton
例如)viewWillDraw
,在其他层中覆盖 init?
并使它们全部成为 wantsLayer
并在这些层上设置属性这充其量看起来极其笨拙,并且一些视觉事物无法以这种方式处理,例如向 NSTextField
添加填充。
我是否应该创建一个
(@Willeke 在评论中告诉我可以选择一个控件的单元格,因此通过再次单击控件来分配自定义单元格类)NSTextFieldCell
子类并实例化一个并将其设置到单元格?这样做会完全破坏文本字段。我看到
other places你应该子类化
NSButtonCell
,但我不能将其指定为 X/Nib 中按钮的类。
很多人都在描述如何通过引用组件来对 viewDidLoad
中的可视组件进行某些更改,如果您的按钮/文本字段样式适用于所有组件,那么这似乎非常乏味。项目。似乎我通过子类化所做的每一次视觉更改都是一场噩梦,而且对于不同组件的视觉更改没有任何模式。如果您想让代码可重用,子类化似乎是任何规模项目的最佳选择,但我是否遗漏了一些东西?我还缺少其他一些模式或习语吗?
最佳答案
子类化 NSTextFieldCell 是最好的选择,但这肯定是一场漫长的战斗。与 Willeke sez 一样,更改 XIB 中单元的类别。
我使用 BGHUDAppKit 作为起点,多年来进行了主要的修改/升级。
FWIW 这是我当前版本的 BGHUDTextFieldCell.mm,它使用了一堆我自己的类别方法,例如 attrStringWithColor,但总体思路应该很清晰。
处理对焦环动画特别麻烦。绘制自定义焦点环的唯一方法是对很多东西进行子类化,包括 NSTextField 及其可能的 super View ,以便您可以劫持默认的 NSTextView 焦点环。但是,我强烈建议不要子类化 NSTextView 本身...请参阅下面的 setupFieldEditorColors。
// BGHUDTextFieldCell.m
// BGHUDAppKit
//
// Created by BinaryGod on 6/2/08.
//
// Copyright (c) 2008, Tim Davis (BinaryMethod.com, binary.god@gmail.com)
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or
// other materials provided with the distribution.
//
// Neither the name of the BinaryMethod.com nor the names of its contributors
// may be used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#import "BGHUDTextFieldCell.h"
#import "VNSColorCategory.h"
#import "BGThemeMbox.h"
@interface BGHUDTextFieldCell (Private)
- (void)doInit;
- (NSRect)_focusRingFrameForFrame:(NSRect)aRect cellFrame:(NSRect)cellFrame; // bug fix
@end
@implementation BGHUDTextFieldCell
@synthesize themeKey;
@synthesize LayerKey;
@synthesize defaultTextColor;
@synthesize isVerticallyCentered;
@synthesize fillsBackground;
//@synthesize LayerKey;
#pragma mark Drawing Functions
- (id)initTextCell:(NSString *)aString {
self = [super initTextCell: aString];
if(self) {
self.themeKey = @"gradientTheme";
[self doInit];
}
return self;
}
- (id)initWithCoder:(NSCoder *) aDecoder {
self = [super initWithCoder: aDecoder];
if(self) {
if([aDecoder containsValueForKey: @"themeKey"]) {
self.themeKey = [aDecoder decodeObjectForKey: @"themeKey"];
} else {
self.themeKey = @"gradientTheme";
}
[self doInit];
}
return self;
}
- (void)doInit
{
self.defaultTextColor = [[[BGThemeManager keyedManager] themeForKey: self.themeKey] textColor];
[self setTextColor:self.defaultTextColor];
if([self drawsBackground]) {
fillsBackground = YES;
////NSLog( @"t%d BGHUDTextFieldCell initTextCell ignoring nib backgroundColor %@, use fillsBackground", [self tag], [self backgroundColor] );
}
else // kpk 2010... always draw background?
{
fillsBackground = NO;
}
[self setDrawsBackground: NO];
}
-(void)encodeWithCoder:(NSCoder *)aCoder {
[super encodeWithCoder: aCoder];
[aCoder encodeObject: self.themeKey forKey: @"themeKey"];
}
- ( NSRect ) adjustFrameToVerticallyCenterText: ( NSRect ) frame
{
// super would normally draw text at the top of the cell
int offset = floor ( ( NSHeight ( frame ) - ( [ [ self font ] ascender] - [ [ self font ] descender ] ) ) / 2 );
frame = NSInsetRect ( frame, 0.0, offset );
return frame;
}
- (NSText *)setUpFieldEditorAttributes:(NSText *)textObj
{
BGTheme *theTheme = [[BGThemeManager keyedManager] themeForKey: self.themeKey];
//textObj = [super setUpFieldEditorAttributes:textObj];
NSTextView *theTextView = (NSTextView *)textObj;
if ( [theTextView isKindOfClass:[NSTextView class]] )
{
//NSLog( @"t%d text view editor %@ bgcolor %@ insert color %@", [self tag], [theTextView description], [theTextView backgroundColor], [theTextView insertionPointColor] );
[BGTheme setupFieldEditorColors:theTheme editor:theTextView window:[[self controlView] window] forObject:self];
}
return textObj;
}
-(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
waitIfNeeded(self);
if ( isVerticallyCentered ) // kpk 2013 _cFlags.vCentered = 1;
cellFrame = [ self adjustFrameToVerticallyCenterText: cellFrame ];
// kpk 2009/2010: get the fieldEditorView (NSTextView) to display properly as well.
// Also be careful not to cause continuous redraws by setting text color unnecessarily.
NSWindow *theWindow = [controlView window];
NSTextView* fieldEditorView = (NSTextView*)[theWindow fieldEditor: NO forObject: self];
id fieldEditorDelegate = [fieldEditorView delegate];
if ( [theWindow firstResponder] == fieldEditorView && fieldEditorDelegate == controlView )
{
//NSLog( @"t%d fieldEditorView bg color %@ self %@ controlView %@", [self tag], [self backgroundColor], [self description], [controlView description] );
BGTheme *theTheme = [[BGThemeManager keyedManager] themeForKey: self.themeKey];
if ( fieldEditorView )
[BGTheme setupFieldEditorColors:theTheme editor:fieldEditorView window:theWindow forObject:self];
NSRect editFrame = [fieldEditorView frame];
NSRect controlViewFrame = [controlView frame];
if ( [controlView isKindOfClass:[NSTextField class]] && NSIntersectsRect(controlViewFrame, editFrame ))
{
return;
}
}
fieldEditorView = nil; // kpk 2010: we are done with this now
//Create Path
NSBezierPath *path = [[NSBezierPath new] autorelease];
if([self bezelStyle] == NSTextFieldRoundedBezel) {
[path appendBezierPathWithArcWithCenter: NSMakePoint(cellFrame.origin.x + (cellFrame.size.height /2), cellFrame.origin.y + (cellFrame.size.height /2))
radius: cellFrame.size.height /2
startAngle: 90
endAngle: 270];
[path appendBezierPathWithArcWithCenter: NSMakePoint(cellFrame.origin.x + (cellFrame.size.width - (cellFrame.size.height /2)), cellFrame.origin.y + (cellFrame.size.height /2))
radius: cellFrame.size.height /2
startAngle: 270
endAngle: 90];
[path closePath];
} else {
// kpk 2010: not desireable for table view cells
//[path appendBezierPathWithRoundedRect: cellFrame xRadius: 3.0f yRadius: 3.0f];
//[path appendBezierPathWithRect:cellFrame];
}
//Draw Background
if(fillsBackground) {
[[[[BGThemeManager keyedManager] themeForKey: self.themeKey] textFillColor] set];
// kpk 2010: not desireable for table view cells
NSRectFill( cellFrame );
//[path fill];
}
else if ( [self isEditable] )
{
[[[[BGThemeManager keyedManager] themeForKey: self.themeKey] textFillColor] set];
[path fill];
// NSRectFill( cellFrame );
}
if([self isBezeled] || [self isBordered]) {
[NSGraphicsContext saveGraphicsState];
if([super showsFirstResponder] && [theWindow isKeyWindow] &&
([self focusRingType] == NSFocusRingTypeDefault ||
[self focusRingType] == NSFocusRingTypeExterior)) {
[[[[BGThemeManager keyedManager] themeForKey: self.themeKey] focusRing] set];
}
//Check State
if([self isEnabled]) {
[[[[BGThemeManager keyedManager] themeForKey: self.themeKey] darkStrokeColor] set];
} else {
[[[[BGThemeManager keyedManager] themeForKey: self.themeKey] disabledStrokeColor] set];
}
[path setLineWidth: 1.0f];
[path stroke];
[NSGraphicsContext restoreGraphicsState];
}
// Check to see if the attributed placeholder has been set or not
//if(![self placeholderAttributedString]) {
if(![self placeholderAttributedString] && [self placeholderString]) {
//Nope lets create it
NSDictionary *attribs = [[NSDictionary alloc] initWithObjectsAndKeys:
[[[BGThemeManager keyedManager] themeForKey: self.themeKey] placeholderTextColor] , NSForegroundColorAttributeName, nil];
//Set it
[self setPlaceholderAttributedString: [[[NSAttributedString alloc] initWithString: [self placeholderString] attributes: [attribs autorelease]] autorelease]];
}
//Adjust Frame so Text Draws correctly
switch ([self controlSize]) {
case NSRegularControlSize:
if([self bezelStyle] == NSTextFieldRoundedBezel) { // kpk 2010
cellFrame.origin.y += 1;
}
break;
case NSSmallControlSize:
if([self bezelStyle] == NSTextFieldRoundedBezel) {
cellFrame.origin.y += 1;
}
break;
case NSMiniControlSize:
if([self bezelStyle] == NSTextFieldRoundedBezel) {
cellFrame.origin.x += 1;
}
break;
default:
break;
}
[self drawInteriorWithFrame: cellFrame inView: controlView];
}
-(void)drawInteriorWithFrame:(NSRect) cellFrame inView:(NSView *) controlView {
if ( [controlView conformsToProtocol:@protocol(EditingAlignmentProtocol)] )
{
if ( [controlView isKindOfClass:[NSControl class]] && [(NSControl *)controlView currentEditor] )
{
// DLog( @"danger: skipping draw to avoid call to validateEditing!" );
return;
}
cellFrame = [(id <EditingAlignmentProtocol>)controlView editingAlignmentRect];
cellFrame = [self titleRectForBounds:cellFrame];
NSAttributedString *str = [self attributedStringValue];
[str drawInRect:cellFrame];
return;
}
[super drawInteriorWithFrame: cellFrame inView: controlView];
}
- (NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
{
// Corbin Dunn (the apple author) says to return nil here
// The proper thing to do:
//
// 1. Subclass NSCell, NSTextFieldCell, or whatever other cell you want.
// 2. Override:
//
// - (NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:(NSView
// *)controlView
//
// and return nil.
//
// That is the correct thing to do for Tiger, Leopard, etc.
//
// corbin
if ( [controlView isKindOfClass: [NSTableView class]] )
return nil; // [[BGThemeMbox instance] cellHighlightColor];
return [super highlightColorWithFrame:cellFrame inView:controlView];
}
// warning mIsEditingOrSelecting is probably not used correctly when call stack is deep,
// while switching from one edit field to another
- (NSRect)drawingRectForBounds:(NSRect)aRect
{
id controlView = [self controlView];
NSRect newRect;
if ( [controlView conformsToProtocol:@protocol(EditingAlignmentProtocol)] )
newRect = [(id <EditingAlignmentProtocol>)controlView editingAlignmentRect];
else
{
newRect = [super drawingRectForBounds:aRect];
if (mIsEditingOrSelecting == NO)
{
// Get our ideal size for current text
NSSize textSize = [self cellSizeForBounds:aRect];
if ( textSize.height >= 22 && textSize.height > newRect.size.height )
{
newRect.origin.y = -(textSize.height - newRect.size.height) + 6;
newRect.size.height = textSize.height + (textSize.height - newRect.size.height);
}
}
}
return newRect;
}
// hack alert: undocumented _focusRingFrameForFrame
// this fixes a hard to reproduce bug where NSTextView fieldEditor *sometimes*
// leaves behind white clutter.
// to reproduce, have 10, 11, or 12 items in scene table, then edit xFade type.
// scene table will have white clutter.
- (NSRect)_focusRingFrameForFrame:(NSRect)aRect cellFrame:(NSRect)cellFrame
{
id ctl = [self controlView];
if ( [ctl conformsToProtocol:@protocol(EditingAlignmentProtocol)] )
return [ctl bounds];
else
return cellFrame;
}
// This method is adapted from Red Sweater Software's RSVerticallyCenteredTextField class.
// Created by Daniel Jalkut on 6/17/06.
// Copyright 2006 Red Sweater Software. All rights reserved.
// MIT License
- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength
{
if ( isVerticallyCentered ) // kpk 2013 _cFlags.vCentered replacement
aRect = [ self adjustFrameToVerticallyCenterText: aRect ];
aRect = [self drawingRectForBounds:aRect];
mIsEditingOrSelecting = YES;
[super selectWithFrame:aRect inView:controlView editor:textObj delegate:anObject start:selStart length:selLength];
mIsEditingOrSelecting = NO;
//NSLog( @"selectWithFrame %@ %@", controlView, textObj );
}
// This method is adapted from Red Sweater Software's RSVerticallyCenteredTextField class.
// Created by Daniel Jalkut on 6/17/06.
// Copyright 2006 Red Sweater Software. All rights reserved.
// MIT License
- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent
{
if ( isVerticallyCentered ) // kpk 2013 _cFlags.vCentered replacement
aRect = [ self adjustFrameToVerticallyCenterText: aRect ];
//NSLog( @"editWithFrame %@", controlView );
aRect = [self drawingRectForBounds:aRect];
mIsEditingOrSelecting = YES;
[super editWithFrame:[self drawingRectForBounds:aRect] inView:controlView editor:textObj delegate:anObject event:theEvent];
mIsEditingOrSelecting = NO;
}
-(void)_drawKeyboardFocusRingWithFrame:(NSRect)fp8 inView:(id)fp24 {
//NSLog( @"_drawKeyboardFocusRingWithFrame" );
}
- (void)drawWithExpansionFrame:(NSRect)cellFrame inView:(NSView *)view
{
[[[[BGThemeManager keyedManager] themeForKey: @"gradientTheme"] darkStrokeColor] set];
NSRectFill(cellFrame);
[self drawInteriorWithFrame:cellFrame inView:view];
}
- (void) setAttributedColor: (NSColor *)iColor
{
NSMutableAttributedString *attrStr = [[self stringValue] attrStringWithColor: iColor];
[attrStr setAlignment: [self alignment] range:[attrStr fullRange]];
[attrStr setFont:[self font]];
[self setAttributedStringValue:attrStr];
if ( iColor )
[self setTextColor:iColor];
else if ( [self isEditable] )
[self setTextColor: [NSColor defaultTextColor]];
else
[self setTextColor:[NSColor dimTextColor]];
}
#pragma mark -
#pragma mark Helper Methods
-(void)dealloc {
[super dealloc];
}
#pragma mark -
@end
.h 文件:
#import <Cocoa/Cocoa.h>
#import "BGThemeManager.h"
@protocol EditingAlignmentProtocol
- (NSRect)editingAlignmentRect; // used to align NSTextView field editor frame
- (void)setIsSettingUpFieldEditor:(bool)flag;
- (bool)isSettingUpFieldEditor;
@end
@interface BGHUDTextFieldCell : NSTextFieldCell {
BOOL fillsBackground;
NSString *themeKey;
NSString *LayerKey;
NSColor *defaultTextColor;
BOOL mIsEditingOrSelecting;
BOOL isVerticallyCentered;
}
@property (retain) NSString *themeKey;
@property (retain) NSString *LayerKey;
@property (retain) NSColor *defaultTextColor;
@property (assign) BOOL isVerticallyCentered;
@property (assign) BOOL fillsBackground;
- (void)doInit; // if overriden, must call [super doInit];
- (void) setAttributedColor: (NSColor *)iColor;
@end
设置字段编辑器
+(void)setupFieldEditorColors:(BGTheme *)iTheme editor:(NSTextView *)iFieldEditorView window:(NSWindow *)iWindow forObject:(id)anObject
{
if ( iFieldEditorView == nil )
return;
if ( !iFieldEditorView || ![iFieldEditorView isKindOfClass:[NSTextView class]] )
return;
// setup attributes such that editing in the field editor will
// occur at the exact same position as the title cell was drawn
[[iFieldEditorView textContainer] setLineFragmentPadding:2.0];
//[[iFieldEditorView layoutManager] setTypesetterBehavior:NSTypesetterBehavior_10_2_WithCompatibility];
NSRange theSelRange = [iFieldEditorView selectedRange];
@try
{
if ( [anObject respondsToSelector: @selector(themeKey)] ||
( [anObject respondsToSelector: @selector(cell)] &&
[[anObject cell] respondsToSelector: @selector(themeKey)] ))
{
//NSLog( @"theSelRange %@", NSStringFromRange(theSelRange));
NSColor *theTextColor = [iTheme textColor];
if ( [iFieldEditorView insertionPointColor] != theTextColor )
[iFieldEditorView setInsertionPointColor:theTextColor];
//if ( [iFieldEditorView textColor] != theTextColor )
//{
//NSLog( @"cell editor tc %@\n change to %@", [iFieldEditorView textColor], theTextColor );
// [iFieldEditorView setTextColor: theTextColor];
//}
//NSLog( @"cell editor createFlag %d", createFlag);
//if ( ![iFieldEditorView isKindOfClass:[BGHUDTextView class]] )
// iFieldEditorView = [BGHUDTextView alloc] init
NSColor *theBgColor = [iTheme cellEditingFillColor];
if ( [iFieldEditorView backgroundColor] != theBgColor )
{
//NSLog( @"cell editor bg %@\n change to %@", [iFieldEditorView backgroundColor], theBgColor );
[iFieldEditorView setBackgroundColor:theBgColor];
}
if ( [iFieldEditorView drawsBackground] == NO )
[iFieldEditorView setDrawsBackground:YES];
NSMutableDictionary *theDict = [[[iFieldEditorView selectedTextAttributes] mutableCopy] autorelease];
//NSColor *theSelTextColor = nil;
if([iWindow isKeyWindow])
{
if ( [theDict objectForKey: NSBackgroundColorAttributeName] != [iTheme selectionHighlightActiveColor] )
{
[theDict setObject: [iTheme selectionHighlightActiveColor]
forKey: NSBackgroundColorAttributeName];
//theSelTextColor = [iTheme selectionTextActiveColor];
//kpk why doesn't this work?
[theDict setObject: [iTheme selectionTextActiveColor]
forKey: NSForegroundColorAttributeName];
[iFieldEditorView setSelectedTextAttributes:theDict];
}
}
else
{
if ( [theDict objectForKey: NSBackgroundColorAttributeName] != [iTheme selectionHighlightInActiveColor] )
{
[theDict setObject: [iTheme selectionHighlightInActiveColor]
forKey: NSBackgroundColorAttributeName];
//theSelTextColor = [iTheme selectionTextInActiveColor];
//kpk why doesn't this work?
[theDict setObject: [iTheme selectionTextInActiveColor]
forKey: NSForegroundColorAttributeName];
[iFieldEditorView setSelectedTextAttributes:theDict];
}
}
/*
NSString *theStr = [iFieldEditorView string];
if ( !theStr )
return;
NSUInteger theStrLength = [theStr length];
if ( theStrLength > 0 )
[iFieldEditorView setTextColor: theTextColor
range: NSMakeRange(0, theStrLength)];
if(theSelRange.length > 0 && theSelRange.length <= theStrLength || theSelRange.location <= theStrLength && NSMaxRange(theSelRange) <= theStrLength )
{
[iFieldEditorView setTextColor: theSelTextColor
range: [iFieldEditorView selectedRange]];
}
else
{
}
*/
}
}
@catch(...)
{
//VLog::Log( kLogErrorType | kLogNoFlood, @"caught exception in setupFieldEditorColors %@", NSStringFromRange(theSelRange));
NSLog( @"caught exception in setupFieldEditorColors %@", NSStringFromRange(theSelRange) );
}
}
关于xcode - 子类化 NSView 子类(NSTextField、NSButton、NSPopUpButton),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37712639/
我正在尝试编写一个应用程序。这将允许用户从一个 NSButton 拖动到另一个。当放下时,我希望将标题拖放到按钮上。 我找不到使 NSButton 可拖动的方法。可能吗? 最佳答案 首先警告:这听起来
我有 2 个 NSButton,都是 IBAction。当我单击其中一个按钮时,我希望隐藏另一个按钮。我可以让他们隐藏自己,但我不知道如何隐藏另一个。我对此的实际实现是有一个“开始”按钮,该按钮会隐藏
我是 Cocoa 编程的初学者。当光标位于按钮上时,如何更改 NSButton 的标题? (无需点击)。 最佳答案 如果您查看 NSButton 的类层次结构,您会发现它派生自 NSResponder
我有一个 viewController xib 文件,我在其中设计了一个具有以下特征的按钮(取自 xib 文件) 现在我希望以编
我有两个 NSButton。两个按钮都带有图像。这就是我创建的[按钮](/image/IYXIE.png),问题是星形按钮始终位于叶子按钮后面。我怎样才能把它带到前面。 (搜索 Mac osx 而不是
我的界面构建器中有两个 nsbutton。对于所有这三个 nsbutton,我都将 Key Equilant 设置为“Return”键。我还为所有这些按钮设置了 nextkey View 。 我对所有
这个问题已经有答案了: NSTextField click-through? (2 个回答) 已关闭 7 年前。 我知道这似乎是一个愚蠢的问题,但它让我很烦恼,这就是为什么我把它放在 Stackove
我有一个 NSButton,它上传文件并解析响应。我想实现以下内容:当我单击按钮时,他上传文件并解析响应。当发生这种情况时,按钮标题应该从“上传”更改为“取消”,当我在上传或解析时再次按下按钮时,解析
如何绘制一个行为大致类似于“邮件”应用中的“已发送”按钮和菜单的 NSButton?它不必是精确的。我只想要带有标签的按钮和没有背景的公开图标,直到用户悬停,然后在下面显示一个菜单。 最佳答案 查看h
我正在尝试在 Xcode 4.6.3 中创建八个自定义按钮 (NSButton)。这些是圆的线段。我为每个部分使用了一个标准的矩形按钮,为每个部分添加了一个自定义图像。但是,当我将各个部分放在一个圆圈
我正在尝试将 NSButton 对焦环颜色设置为白色。目前,当按钮有firstResponder时,它显示蓝色轮廓。 我知道有 drawFocusRingMaskWithFrame:inView:来帮
我正在尝试在 IB 中创建一个原生 NSButton 对象。当我选择附件作为按钮类型时,标题消失。当我尝试编写标题时,按钮没有调整大小,并且三角形不断消失。 如何制作一个 NSButton,其右侧带有
我写了一些糟糕的代码,但它有效。有更好的方法来写这个吗? _decade.x 是 NSButton。 int baseDecade = 1940; NSString *title; int curre
我有一个自定义的 NSButton,但无论我做什么,禁用的颜色始终是灰色的 我尝试了遇到的所有解决方案 我正在将属性字符串标题设置为白色前景色(我看起来颜色属性在禁用状态下被忽略) 我确实设置了 [[
我使用带有自定义背景的标准 NSButton。黑色标题颜色有白色阴影 - 如何删除它? 图片: http://i.piccy.info/i7/f4ae52b56aad922f0129e4b6bd868
我有一个问题。我的 .xib 上有一个按钮和一个背景图像。我通过属性检查器为按钮设置了图像,但是当我运行程序并按下按钮时,会发生这种情况: 如果我不按它,看起来就很好。怎么了? 最佳答案 这由单元格上
在Mac应用程序中,我使用具有渐变样式、无边框和自定义图像作为背景的NSButton。问题是,单击按钮时,可以看到按钮周围的矩形白色区域。如何可以不显示吗? 谢谢 LS 开发者 最佳答案 您需要将按钮
我无法在我以编程方式创建的 NSButton 上进行关键的等效工作。谁能告诉我我做错了什么?按下按钮后,该按钮将按预期工作,但等效键将不起作用。 NSButton *ESCButton = [[NSB
如何创建一个具有非方形“点击区域”的 NSButton? 示例: 谢谢。 最佳答案 您可能可以子类化 NSButton 并重写 hitTest: 以在位于您希望可点击的区域之外时返回 nil。 (进入
我试图在鼠标按下按钮时显示弹出菜单。当鼠标按下时,按钮应显示为按下状态,而当鼠标松开时,按钮应显示为“未按下”,无论选择了任何菜单项。类似于“Expose/Space Preference”面板中用于
我是一名优秀的程序员,十分优秀!